|
Dear Listers, I have written a Python routine that shall delete a value label. The workaround with ADD VALUE LABELS <value> "" does not work in our case here. For this Python routine we use spssaux.GetValueLabel. But this routine does not deliver the value that is defined as user missing. The labels transcribed from the SPSS GUI Variable View are as follows 1 'less than 5'
If I call spssaux.GetValueLabels(varindex = 5, matchtype = True) I get the following dictionary as result {1.0: 'less than 5', 2.0: 'less than 13', 3.0: 'less than 25', 4.0: 'less than 48', 5.0: '48 and more', 88.0: 'No Answer'} This is the direct output of the result of the function without any modifications from my side. What I would have expected is {1.0: 'less than 5', 2.0: 'less than 13', 3.0: 'less than 25', 4.0: 'less than 48', 5.0: '48 and more', 88.0: '', 99: 'No answer'} I had a look into the source code for GetValueLabels from SPSS and found that they are using DISPLAY DICTIONARY /VARIABLES = <var> and catch the output using the OMS command written to an XML data structure from where it is put back into Python . If I run DISPLAY DICTIONARY /VARIABLES = <var> as SPSS syntax the missing value is shown correctly as follows: 1 'less than 5'
Can anybody give me a hint how to fix that? Best regards Georg |
|
Hi Georg, I ran two programs against the employee data.sav dataset using V18, and both ways included the value label for a missing value. begin program. import spss, spssaux vardict = spssaux.VariableDict() vallbls = vardict['jobcat'].ValueLabels print vallbls end program. with output {u'1': u'Clerical', u'0': u'0 (Missing)', u'3': u'Manager', u'2': u'Custodial'} begin program. import spss, spssaux vallbls = spssaux.GetValueLabels(varindex=4, matchtype=True) print vallbls end program. with output {0.0: u'0 (Missing)', 1.0: u'Clerical', 2.0: u'Custodial', 3.0: u'Manager'} I tried it also with two user missing values, and both showed up. Poking around further, I find that an empty and footnoted label, which now appears in the output table as <none> is not picked up by the Xpath expression in spssaux.getValueLabels. Try changing the line in spssaux.getValueLabels from labpath = "pivotTable[@subType='Variable Values']/dimension/group/category/@label" to labpath = """pivotTable[@subType='Variable Values']/dimension/group/category/dimension[@text='Label']//cell/@text""" I need to test this further but will update the spssaux module once that is done. Note that the empty label will appear as <none>. Jon Peck SPSS, an IBM Company [hidden email] 312-651-3435
Dear Listers, I have written a Python routine that shall delete a value label. The workaround with ADD VALUE LABELS <value> "" does not work in our case here. For this Python routine we use spssaux.GetValueLabel. But this routine does not deliver the value that is defined as user missing. The labels transcribed from the SPSS GUI Variable View are as follows 1 'less than 5' If I call spssaux.GetValueLabels(varindex = 5, matchtype = True) I get the following dictionary as result {1.0: 'less than 5', 2.0: 'less than 13', 3.0: 'less than 25', 4.0: 'less than 48', 5.0: '48 and more', 88.0: 'No Answer'} This is the direct output of the result of the function without any modifications from my side. What I would have expected is {1.0: 'less than 5', 2.0: 'less than 13', 3.0: 'less than 25', 4.0: 'less than 48', 5.0: '48 and more', 88.0: '', 99: 'No answer'} I had a look into the source code for GetValueLabels from SPSS and found that they are using DISPLAY DICTIONARY /VARIABLES = <var> and catch the output using the OMS command written to an XML data structure from where it is put back into Python . If I run DISPLAY DICTIONARY /VARIABLES = <var> as SPSS syntax the missing value is shown correctly as follows: 1 'less than 5' Can anybody give me a hint how to fix that? Best regards Georg
|
| Free forum by Nabble | Edit this page |
