|
Is there a way in syntax to create value labels by associating value indicators from one variable to labels in another?
For example, say I have two variables, V1 is the numeric code & V2 is the alpha value label. V1 V2 23 biology 47 chemistry 13 anthropology It would be nice to have syntax that would help produce: val lab 23 'biology' 47 'chemistry' 13 'anthropology' Perhaps if there was a way to push the above to output, don't know, I suspect I could aggregate on V1 in an output file & cut/paste with some inserts for formatting. Any ideas on automating this one? Thanks in advance, David ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
Is there some reason why you have to have biology=23? If you use autorecode, it will take the existing value and give it a numerical code based upon an alpha sort.
-----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Wright Sent: Wednesday, December 10, 2008 2:24 PM To: [hidden email] Subject: auto creating labels Is there a way in syntax to create value labels by associating value indicators from one variable to labels in another? For example, say I have two variables, V1 is the numeric code & V2 is the alpha value label. V1 V2 23 biology 47 chemistry 13 anthropology It would be nice to have syntax that would help produce: val lab 23 'biology' 47 'chemistry' 13 'anthropology' Perhaps if there was a way to push the above to output, don't know, I suspect I could aggregate on V1 in an output file & cut/paste with some inserts for formatting. Any ideas on automating this one? Thanks in advance, David ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
In reply to this post by wsu_wright
There is no built-in way to do this, but there is a function available in the spssaux2 module called genValueLabels that will do it. For example,
BEGIN PROGRAM. import spss, spssaux2 conflictKt = spssaux2.genValueLabels("V1", "V2") print conflictKt END PROGRAM. This creates a value label set for V1 based on the associated V2 values (variable name case matters). conflictKt is a count of the number of inconsistent pairs. So if you had V1 V2 1 biology 1 BIOLOGY you would get a nonzero count. This requires, of course, the Python plug-in and the spssaux2.py module downloadable from SPSS Developer Central (www.spss.com/devcentral). HTH, Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Wright Sent: Wednesday, December 10, 2008 2:24 PM To: [hidden email] Subject: [SPSSX-L] auto creating labels Is there a way in syntax to create value labels by associating value indicators from one variable to labels in another? For example, say I have two variables, V1 is the numeric code & V2 is the alpha value label. V1 V2 23 biology 47 chemistry 13 anthropology It would be nice to have syntax that would help produce: val lab 23 'biology' 47 'chemistry' 13 'anthropology' Perhaps if there was a way to push the above to output, don't know, I suspect I could aggregate on V1 in an output file & cut/paste with some inserts for formatting. Any ideas on automating this one? Thanks in advance, David ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
In reply to this post by ViAnn Beadle
Yes, the numeric values need to be associated with the specific labels. I too thought about the autorecode function but noticed it wouldn't honor the association. I have several of these some of which have dozens of labels. I'm currently exporting the aggregated output on the numeric into excel where I perform a concatenate of the numeric & label with formatting & then copy back into syntax.
Hmm, perhaps the same would work, here, could I aggregate by the numeric, create a string by concatenating the numeric & values (creating a string for the ') & then copy back into the syntax, sorry thinking out loud. DW ---- ViAnn Beadle <[hidden email]> wrote: > Is there some reason why you have to have biology=23? If you use autorecode, it will take the existing value and give it a numerical code based upon an alpha sort. > > -----Original Message----- > From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Wright > Sent: Wednesday, December 10, 2008 2:24 PM > To: [hidden email] > Subject: auto creating labels > > Is there a way in syntax to create value labels by associating value indicators from one variable to labels in another? > > For example, say I have two variables, V1 is the numeric code & V2 is the alpha value label. > > V1 V2 > 23 biology > 47 chemistry > 13 anthropology > > It would be nice to have syntax that would help produce: > > val lab > 23 'biology' > 47 'chemistry' > 13 'anthropology' > > Perhaps if there was a way to push the above to output, don't know, I suspect I could aggregate on V1 in an output file & cut/paste with some inserts for formatting. Any ideas on automating this one? > > Thanks in advance, > > David > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD > ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
In reply to this post by wsu_wright
It is surely programmable with Python in a very elegant way. A more
primitive approach is producing the list of values both variables (e.g. by ordering a frequencies Table), make sure each numeric code in V1 corresponds to the alphabetic code in V2, then copy-paste the results to Excel, delete the frequencies and percentage columns, insert two narrow columns for the apostrophes, et voila: just add the command at the begginning (VALUE LABEL V1) and a period at the end. As I do not face this kind of problem often, I thought it was not worthwhile to trouble myself programming it: this quick and dirty copy-paste solution I find fast enough. At least in my "Keep it simple" mentality. Hector -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Wright Sent: 10 December 2008 19:24 To: [hidden email] Subject: auto creating labels Is there a way in syntax to create value labels by associating value indicators from one variable to labels in another? For example, say I have two variables, V1 is the numeric code & V2 is the alpha value label. V1 V2 23 biology 47 chemistry 13 anthropology It would be nice to have syntax that would help produce: val lab 23 'biology' 47 'chemistry' 13 'anthropology' Perhaps if there was a way to push the above to output, don't know, I suspect I could aggregate on V1 in an output file & cut/paste with some inserts for formatting. Any ideas on automating this one? Thanks in advance, David ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
In reply to this post by ViAnn Beadle
ViAnn, that is often the case. I faced the problem, for instance, with the
international codes for occupations and industries, and with a country's standard numerical codes for provinces and districts. Recode would not do: you must preserve the original numeric codes. Hector -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of ViAnn Beadle Sent: 10 December 2008 19:32 To: [hidden email] Subject: Re: auto creating labels Is there some reason why you have to have biology=23? If you use autorecode, it will take the existing value and give it a numerical code based upon an alpha sort. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Wright Sent: Wednesday, December 10, 2008 2:24 PM To: [hidden email] Subject: auto creating labels Is there a way in syntax to create value labels by associating value indicators from one variable to labels in another? For example, say I have two variables, V1 is the numeric code & V2 is the alpha value label. V1 V2 23 biology 47 chemistry 13 anthropology It would be nice to have syntax that would help produce: val lab 23 'biology' 47 'chemistry' 13 'anthropology' Perhaps if there was a way to push the above to output, don't know, I suspect I could aggregate on V1 in an output file & cut/paste with some inserts for formatting. Any ideas on automating this one? Thanks in advance, David ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
In reply to this post by Hector Maletta
Hector,
Yes, this is the method I do now. Unfortunately, I get several of these types of data. Jon, as you did, suggested the pyhton route but I would like to avoid it. I recently sent a reply ViAnn concerning perhaps another option, the code would perhaps be a bear but once set I could use, just not sure it would work. I was thinking after addressing her question that perhaps I could aggregate an output on the numeric bringing over the alpha label, create a new string by concatenating the altered numeric & label (also creatinga string for the apostrohpe), then I could cut & paste from the aggregated data editor into the syntax file. What do you think? DW ---- Hector Maletta <[hidden email]> wrote: > It is surely programmable with Python in a very elegant way. A more > primitive approach is producing the list of values both variables (e.g. by > ordering a frequencies Table), make sure each numeric code in V1 corresponds > to the alphabetic code in V2, then copy-paste the results to Excel, delete > the frequencies and percentage columns, insert two narrow columns for the > apostrophes, et voila: just add the command at the begginning (VALUE LABEL > V1) and a period at the end. > As I do not face this kind of problem often, I thought it was not worthwhile > to trouble myself programming it: this quick and dirty copy-paste solution I > find fast enough. At least in my "Keep it simple" mentality. > Hector > > > -----Original Message----- > From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of > David Wright > Sent: 10 December 2008 19:24 > To: [hidden email] > Subject: auto creating labels > > Is there a way in syntax to create value labels by associating value > indicators from one variable to labels in another? > > For example, say I have two variables, V1 is the numeric code & V2 is the > alpha value label. > > V1 V2 > 23 biology > 47 chemistry > 13 anthropology > > It would be nice to have syntax that would help produce: > > val lab > 23 'biology' > 47 'chemistry' > 13 'anthropology' > > Perhaps if there was a way to push the above to output, don't know, I > suspect I could aggregate on V1 in an output file & cut/paste with some > inserts for formatting. Any ideas on automating this one? > > Thanks in advance, > > David > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
In reply to this post by Peck, Jon
There is a way to do this without resorting to Python, but it's arguably not as elegant as using Python. It involves using the WRITE command to generate a syntax file and then running the syntax file via INSERT, as in:
write outfile='/temp/tempfile.sps' / "add value labels v1 ", v1, " '", v2, "'.". execute. insert file= '/temp/tempfile.sps'. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Peck, Jon Sent: Wednesday, December 10, 2008 3:40 PM To: [hidden email] Subject: Re: auto creating labels There is no built-in way to do this, but there is a function available in the spssaux2 module called genValueLabels that will do it. For example, BEGIN PROGRAM. import spss, spssaux2 conflictKt = spssaux2.genValueLabels("V1", "V2") print conflictKt END PROGRAM. This creates a value label set for V1 based on the associated V2 values (variable name case matters). conflictKt is a count of the number of inconsistent pairs. So if you had V1 V2 1 biology 1 BIOLOGY you would get a nonzero count. This requires, of course, the Python plug-in and the spssaux2.py module downloadable from SPSS Developer Central (www.spss.com/devcentral). HTH, Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Wright Sent: Wednesday, December 10, 2008 2:24 PM To: [hidden email] Subject: [SPSSX-L] auto creating labels Is there a way in syntax to create value labels by associating value indicators from one variable to labels in another? For example, say I have two variables, V1 is the numeric code & V2 is the alpha value label. V1 V2 23 biology 47 chemistry 13 anthropology It would be nice to have syntax that would help produce: val lab 23 'biology' 47 'chemistry' 13 'anthropology' Perhaps if there was a way to push the above to output, don't know, I suspect I could aggregate on V1 in an output file & cut/paste with some inserts for formatting. Any ideas on automating this one? Thanks in advance, David ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
In reply to this post by wsu_wright
Here's a solution I used a couple times pre-Python days that I think
does what you're looking for (if I understand what you're trying to do correctly). It came from SPSS Support a few years ago. Resolution number: 31573 Created on: Feb 24 2003 Last Reviewed on: Dec 26 2007 Problem Subject: Creating value labels from the values of a separate variable in SPSS Problem Description: I am using SPSS for Windows and I would like to automatically create value labels for one variable from the values of another variables. How can I do this? Resolution Subject: The following syntax commands will produce value labels from your file data Resolution Description: Below is some syntax that will show you how to do this. The syntax will create a sample data file and apply the values of v2 as value labels of v1. *This will create a sample data set. *The data set needs to be aggregated down so there is a 1-1 relationship between value and value label. DATA LIST FREE /v1 (F1) v2 (A1). BEGIN DATA 1 a 2 b 3 c 4 d 5 e END DATA. /*This section will write out the words value labels and the variable name in the valuelabel.dat file.*/ DO IF ($casenum=1). WRITE OUTFILE = 'c:\temp\valuelabel.dat'/ 'VALUE LABELS v1'. END IF. /*This section will write out the values and value labels in the valuelabel.dat file.*/ WRITE OUTFILE = 'c:\temp\valuelabel.dat'/ ' ' v1 " '" v2 "' ". EXECUTE. INCLUDE 'c:\temp\valuelabel.dat'. Dan -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Wright Sent: Wednesday, December 10, 2008 2:03 PM To: [hidden email] Subject: Re: auto creating labels Hector, Yes, this is the method I do now. Unfortunately, I get several of these types of data. Jon, as you did, suggested the pyhton route but I would like to avoid it. I recently sent a reply ViAnn concerning perhaps another option, the code would perhaps be a bear but once set I could use, just not sure it would work. I was thinking after addressing her question that perhaps I could aggregate an output on the numeric bringing over the alpha label, create a new string by concatenating the altered numeric & label (also creatinga string for the apostrohpe), then I could cut & paste from the aggregated data editor into the syntax file. What do you think? DW ---- Hector Maletta <[hidden email]> wrote: > It is surely programmable with Python in a very elegant way. A more > primitive approach is producing the list of values both variables (e.g. by > ordering a frequencies Table), make sure each numeric code in V1 corresponds > to the alphabetic code in V2, then copy-paste the results to Excel, delete > the frequencies and percentage columns, insert two narrow columns for the > apostrophes, et voila: just add the command at the begginning (VALUE LABEL > V1) and a period at the end. > As I do not face this kind of problem often, I thought it was not worthwhile > to trouble myself programming it: this quick and dirty copy-paste solution I > find fast enough. At least in my "Keep it simple" mentality. > Hector > > > -----Original Message----- > From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of > David Wright > Sent: 10 December 2008 19:24 > To: [hidden email] > Subject: auto creating labels > > Is there a way in syntax to create value labels by associating value > indicators from one variable to labels in another? > > For example, say I have two variables, V1 is the numeric code & V2 is the > alpha value label. > > V1 V2 > 23 biology > 47 chemistry > 13 anthropology > > It would be nice to have syntax that would help produce: > > val lab > 23 'biology' > 47 'chemistry' > 13 'anthropology' > > Perhaps if there was a way to push the above to output, don't know, I > suspect I could aggregate on V1 in an output file & cut/paste with > inserts for formatting. Any ideas on automating this one? > > Thanks in advance, > > David > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
In reply to this post by wsu_wright
Is this what you want to do?
open a new instance of SPSS. Copy the syntax below. paste it into a syntax window. Run it. you can copy the output from the new syntax output file to your syntax file. data list list /V1 (f2) V2(a20). begin data 23 biology 47 chemistry 13 anthropology end data. do if $casenum eq 1. print / 'value labels newvar'. end if. PRINT / ' ' v1 ' "' v2 ' " '. execute. Art Kendall Social Research Consultants David Wright wrote: > Is there a way in syntax to create value labels by associating value indicators from one variable to labels in another? > > For example, say I have two variables, V1 is the numeric code & V2 is the alpha value label. > > V1 V2 > 23 biology > 47 chemistry > 13 anthropology > > It would be nice to have syntax that would help produce: > > val lab > 23 'biology' > 47 'chemistry' > 13 'anthropology' > > Perhaps if there was a way to push the above to output, don't know, I suspect I could aggregate on V1 in an output file & cut/paste with some inserts for formatting. Any ideas on automating this one? > > Thanks in advance, > > David > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD > > > ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Art Kendall
Social Research Consultants |
|
In reply to this post by Peck, Jon
John, will this work in V15?
Garry -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Peck, Jon Sent: 10 December 2008 21:40 To: [hidden email] Subject: Re: auto creating labels There is no built-in way to do this, but there is a function available in the spssaux2 module called genValueLabels that will do it. For example, BEGIN PROGRAM. import spss, spssaux2 conflictKt = spssaux2.genValueLabels("V1", "V2") print conflictKt END PROGRAM. This creates a value label set for V1 based on the associated V2 values (variable name case matters). conflictKt is a count of the number of inconsistent pairs. So if you had V1 V2 1 biology 1 BIOLOGY you would get a nonzero count. This requires, of course, the Python plug-in and the spssaux2.py module downloadable from SPSS Developer Central (www.spss.com/devcentral). HTH, Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Wright Sent: Wednesday, December 10, 2008 2:24 PM To: [hidden email] Subject: [SPSSX-L] auto creating labels Is there a way in syntax to create value labels by associating value indicators from one variable to labels in another? For example, say I have two variables, V1 is the numeric code & V2 is the alpha value label. V1 V2 23 biology 47 chemistry 13 anthropology It would be nice to have syntax that would help produce: val lab 23 'biology' 47 'chemistry' 13 'anthropology' Perhaps if there was a way to push the above to output, don't know, I suspect I could aggregate on V1 in an output file & cut/paste with some inserts for formatting. Any ideas on automating this one? Thanks in advance, David ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD __________ NOD32 3682 (20081210) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
| Free forum by Nabble | Edit this page |
