Jon
You kindly supplied Python code for a subset of the NORC GSS which changes all upper case labels to lower case, but leaves value labels IAP, DK and NA unchanged.
/*Changes all letters to lower case, except IAP DK and NA.
begin program.
import spss, spssaux
vardict = spssaux.VariableDict()
for var in vardict:
var.VariableLabel = var.VariableLabel.lower()
vallabels = var.ValueLabels
for k,v in vallabels.items():
if not v in ['IAP', 'DK', 'NA']:
vallabels[k] = v.lower()
var.ValueLabels = vallabels
end program.
You then supplied the following code to change the first letter of every label back to upper case: this works, but changes IAP DK and NA to Iap, Dk, and Na.
/*Restores first letter of first word to upper case
begin program.
import spss, spssaux
vd = spssaux.VariableDict()
for v in vd:
varlabel = v.VariableLabel
if varlabel:
v.VariableLabel = varlabel.capitalize()
vallbls = v.ValueLabels
for k in vallbls:
vallbls[k] = vallbls[k].capitalize()
if vallbls:
v.ValueLabels = vallbls
end program.
I’ve been trying for ages to tweak the second set of code to leave IAP, DK and NA unchanged, but admit defeat. Is there any way the two can be combined?
This would still leave a few labels to pick up for words like christian, american, islam etc., but this can be done with VALUE LABELS.
This is for the full NORC General Social Survey 2008. The SPSS saved file as distributed already has most variable names in lower case, but some are in upper case: most of these latter already have some variable and value labels in mixed case (possibly because they are derived variables or have been used in secondary analysis) but the Python code doesn’t affect these. Once I’ve got it sorted, the same modifications can then be made to all surveys in the series from 1972 to present.
John
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