|
In the SPSS saved file for the 2008 European Values Survey (Great Britain only) as downloaded from GESIS, almost all variable and value labels start with a lower case letter. For every variable the question number always appears in brackets at the end of the label: Var labs: how important in your life: work (Q1A) how important in your life: family (Q1B) how important in your life: friends and acquaintances (Q1C) how important in your life: leisure time (Q1D) how important in your life: politics (Q1E) how important in your life: religion (Q1F) how often discuss politics with friends (Q2) taking all things together how happy are you (Q3) describe your state of health these days (Q4) Val labs: -5 other missing -4 question not asked -3 NAP -2 NA -1 DK 1 very important ~ ~ 4 not at all important Missing values are the same, and consistently labelled, for every variable in the list. I tried the following Python code (from Jon Peck for an earlier, but similar problem): begin program. import spss, spssaux vardict = spssaux.VariableDict() for var in vardict: var.VariableLabel = var.VariableLabel.title() vallabels = var.ValueLabels for k,v in vallabels.items(): if not v in ['IAP', 'DK', 'NA']: vallabels[k] = v.title() var.ValueLabels = vallabels end program. . . which changes the 1st letter of every variable and value label to upper case, but also changes the letters in the question number to lower case: How important in your life: work (q1a) How important in your life: family (q1b) How important in your life: friends and acquaintances (q1c) How important in your life: leisure time (q1d) How important in your life: politics (q1e) How important in your life: religion (q1f) How often discuss politics with friends (q2) Taking all things together how happy are you (q3) Describe your state of health these days (q4) -5 Other missing -4 Question not asked --3 Nap -2 Na -1 Dk 1 Very important ~ ~ 4 Not at all important No problem to highlight the Labels column, then use CTRL+H to change (q to (Q. and then highlight the Values column and use CTRL+H to change Nap, Na, Dk to NAP, NA and DK throughout (or Not applicable, Not answered, and Don’t know) but how can I get all the question numbers to the beginning of the labels? Why do I want to do this? Because in the GUI pop-out menus variable names are not easy to identify with questions when the settings are for names: it’s easier to locate variables if the settings are for labels and the question number appears in the panes without having to stretch the window out. Jon provided some code to do that for another survey, but the format of the question numbers was much more complex. These are straightforward and bracketed, except that some have a suffix added for items in batteries, eg: do you belong to: welfare organisation (Q5aA) do you belong to: religious organisation (Q5aB) do you belong to: cultural activities (Q5aC) do you belong to: trade unions (Q5aD) do you belong to: political parties/groups (Q5aE) do you belong to: local community action (Q5aF) ~ ~ ~ gets changed to: Do you belong to: welfare organisation (q5aa) Do you belong to: religious organisation (q5ab) Do you belong to: cultural activities (q5ac) Do you belong to: trade unions (q5ad) Do you belong to: political parties/groups (q5ae) Do you belong to: local community action (q5af) ~ ~ ~ . . when what is needed is: (Q5aA) Do you belong to: welfare organisation (Q5aB) Do you belong to: religious organisation (Q5aC) Do you belong to: cultural activities (Q5aD) Do you belong to: trade unions (Q5aE) Do you belong to: political parties/groups (Q5aF) Do you belong to: local community action ~ ~ ~ Jon’s Python code for the British Social Attitudes Survey was: begin program. import spss,re from spssaux import _smartquote for v in range(spss.GetVariableCount()): vname = spss.GetVariableName(v) vlabel = spss.GetVariableLabel(v) vl = [] # Find the question number and move to front mo = re.match(r"(.*)(:Q)(\d+).*", vlabel) if not mo is None: vl.append("Q." + mo.group(3) + ": ") vl.append(mo.group(1)) hasq = True else: # no Q-style question number. Check for multiple questions hasq = False mo = re.match(r"(.*)(a2\..*)", vlabel, flags=re.I) if not mo is None: # multiple q's vl.append(mo.group(2) + ": ") vl.append(mo.group(1)) mo = re.match(r"(.*)(b2\..*)", vlabel, flags=re.I) if not mo is None: # multiple q's vl.append(mo.group(2) + ": ") vl.append(mo.group(1)) if len(vl) == 0: vl.append("") vl.append(vlabel) # capitalize first letter of label excluding the Q number vl[-1] = vl[-1][0].upper() + vl[-1][1:] # find freestanding "dv" mo = re.search(r"(.*)(\bdv\b)(.*)", vl[1], flags=re.I) if not mo is None: if hasq: vlabel = vl[0] + "(dv) " + mo.group(1) else: if vl[0] != "": vl[0] = "(dv) " + vl[0] vlabel = vl[0] + mo.group(1) + mo.group(3) else: vlabel = "(dv) " + mo.group(1) + mo.group(3) else: vlabel = vl[0] + vl[1] spss.Submit("""variable label %s %s.""" % (vname, _smartquote(vlabel))) end program. . . but I’m too much of a coward try it, and too much of a novice to attempt to modify it. The labelling system is the same for all European Values and also World Values surveys, regardless of language or country, so the resulting Python code will apply to all of them and make life much easier for other users, especially if they have the pdf questionnaire alongside. Season’s greetings to one and all from storm-swept Lower Normandy. John F Hall (Mr) [Retired academic survey researcher] Email: [hidden email] Website: www.surveyresearch.weebly.com SPSS start page: www.surveyresearch.weebly.com/1-survey-analysis-workshop |
| Free forum by Nabble | Edit this page |
