Hi all, Would appreciate your help again. I’m trying to create a dichotomous variable to categorize cases where people bought a certain “higher-end” product (var2 which is a string) in a particular year (between 2002 to 2009) . If the two conditions are met, the case would be marked YES. If either var1 and/or var2 are “blank” then the case is marked NO; and if var2 isn’t a “higher-end” product, the case would also be marked NO. (There are no cases listing a year but no product.) Thanks very much for your help. elle
|
<base href="x-msg://4/">
I'm new to this... What to do? Coding something very routine -- Value Labels -- and for the first time ever... I tried starting over; that is, opening an Excel file, saving it as spss data file; opening new sytax VALUE LABELS Q21 1 "No" 2 "Part time" 3 "Full time" 0 “NR”. VALUE LABELS Q22 1 "<3 months" 2 ">3 months but<6 months" 3 ">6 months but <12 months" 4 ">12 months but <2 years" 5 "2 years or more" 0 “NR”. VALUE LABELS Q23 1 "Business" 2 "Communications" 3 "Education" 4 "Finance" 5 "Information Technology" 6 "Insurance" 7 "Manufacturing" 8 "Medical" 9 "Nonprofit" 10 "Retail" 0 “NR”. VALUE LABELS Q24 1 "Transgender" 2 "Male" 3 "Female" 0 “NR”. VALUE LABELS Q25 1 "No" 2 "Yes" 0 “NR”. VALUE LABELS Q26 1 "Asian" 2 "Black or African American" 3 "American Indian or Alaska Native" 4 "White" 5 "Other" 0 “NR”. VALUE LABELS Q27 1 "18 to 30" 2 "31 to 50" 3 "51 to 65" 4 "over 65" 0 “NR”. VALUE LABELS Q28 1 "Protestant" 2 "Catholic" 3 "Mormon" 4 "Orthodox" 5 "Jewish" 6 "Muslim" 7 "Buddhist" 8 "Hindu" 9 "Atheist" 10 "Agnostic" 11 “Other” 12 “None” 0 “NR”. VALUE LABELS Q29 1 "No" 2 "Yes" 0 “NR”. Each variable, for which I am trying to create value labels, is a transformed variable. For example: COMPUTE Q21= (V2*2) + (V3*3) + (V4*1). Dona
|
In reply to this post by elle lists
Why are you working with strings? Numeric vars are so much easier. Have a look at AUTORECODE in the syntax reference guide (Click on help > guide) This will convert var2 and var3 into numeric vars and save you a lot of typing. You can then use COUNT and other commands to generate the values you want. John F Hall From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of elle Hi all, Would appreciate your help again. I’m trying to create a dichotomous variable to categorize cases where people bought a certain “higher-end” product (var2 which is a string) in a particular year (between 2002 to 2009) . If the two conditions are met, the case would be marked YES. If either var1 and/or var2 are “blank” then the case is marked NO; and if var2 isn’t a “higher-end” product, the case would also be marked NO. (There are no cases listing a year but no product.) Thanks very much for your help. elle
|
Dear friend Strange .. Case 1 and 16 contradict each other ... suntaxe was doing but I was in doubt.
Carlos Renato
Statistician - Brazil
|
Administrator
|
In reply to this post by elle lists
The example you show below does not make it clear (to me, at least) what the rule is. E.g., you have some cases flagged YES despite having no data for Year (VAR1). That doesn't make sense, given what you've said.
As John F suggested, you could begin by using AUTORECODE to get a numeric version of your VAR2. Then, you want something like: compute #cond1 = any(NumericVar2,value1,value2,value3, ..., valueX). compute #cond2 = range(VAR1,2002,2009). compute var3 = #cond1 AND #cond2. formats var3 (f1.0). value labels var3 1 'Yes' 0 'No'. In the first COMPUTE line above: NumericVar2 is a numeric version of your Var2, obtained via AUTORECODE; value1, value2, etc are the values of NumericVar2 that are your "certain higher-end products". HTH.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
In reply to this post by elle lists
Thank you, Bruce Weaver, John Hall, Carlos Renato, and Melissa Ives, for responding to my question. My apologies for posting the example which showed cases 16 and 19 incorrectly flagged as YES (should have been NO) – the corrected table is posted below. Thanks to Melissa Ives for the first posting with an untested syntax. Running the syntax, however, generated an error (per Carlo’s observation) which seems to have been related to the string variable. John Hall’s observation about converting the string to numeric (Automatic Recode) helped to clear the path towards concocting a syntax. (The string variable is one of several in this data set but I now see how much easier it is to convert and work with a numeric format.) I was able to concoct a very beginner’s “sad-but-works” syntax (below) so Bruce Weaver’s solution/summary is very welcome (!) and informative (!) instruction on the process. His solution is reposted here: >As John F suggested, you could begin by using AUTORECODE to get a numeric version of your VAR2. >Then, you want something like: >compute #cond1 = any(NumericVar2,value1,value2,value3, ..., valueX). >compute #cond2 = range(VAR1,2002,2009). >compute var3 = #cond1 AND #cond2. >formats var3 (f1.0). >value labels var3 1 'Yes' 0 'No'. Thanks to all for taking the time and interest. elle
My torturous syntax/procedure: 1.Autocode the string variable (VAR2) to a numeric variable (VAR2num). (var2num has values 1-9; blank cells/no product purchase is identified as “1”.) AUTORECODE VARIABLES=VAR2 /INTO var2num /PRINT. 2.Converting 4-digit year (VAR1) to a single-digit variable (var1b)equaling “1”. RECODE VAR1 (2008=1) (2004=1) (2003=1) INTO var1b. EXECUTE. 3. Adding var2num with var1b. (To identify values that are either 1 or >1). EXECUTE. 4. Recoding VAR3 where values: > 1 is converted to “1” else =0. RECODE VAR3 (2=1) (3=1) (4=1) (5=1) (6=1) (7=1) (8=1) (9=1) (ELSE=0) INTO VAR4. EXECUTE. VALUE LABELS 1='yes' 0='n. EXECUTE. -----Original Message----- The example you show below does not make it clear (to me, at least) what the rule is. E.g., you have some cases flagged YES despite having no data for Year (VAR1). That doesn't make sense, given what you've said. As John F suggested, you could begin by using AUTORECODE to get a numeric version of your VAR2. Then, you want something like: compute #cond1 = any(NumericVar2,value1,value2,value3, ..., valueX). compute #cond2 = range(VAR1,2002,2009). compute var3 = #cond1 AND #cond2. formats var3 (f1.0). value labels var3 1 'Yes' 0 'No'. In the first COMPUTE line above: NumericVar2 is a numeric version of your Var2, obtained via AUTORECODE; value1, value2, etc are the values of NumericVar2 that are your "certain higher-end products". HTH. elle lists wrote: > > Hi all, > > > > Would appreciate your help again. I'm trying to create a dichotomous > variable to categorize cases where people bought a certain "higher-end" > product (var2 which is a string) in a particular year (between 2002 to > 2009) > . If the two conditions are met, the case would be marked YES. If > either var1 and/or var2 are "blank" then the case is marked NO; and if > var2 > isn't a "higher-end" product, the case would also be marked NO. > (There are no cases listing a year but no product.) > > > > Thanks very much for your help. > > > > elle |
Administrator
|
Elle,
I would *NOT* bother with AUTORECODE in such a case!! What happens when you add other data and the codes are *NOT* the exactly same? You then need to track down the appropriate codes and rewrite the relevant syntax. Sometimes strings are *EASIER* than dealing with numerics (if that is how your data arrive). In other words, the current approach is *FRAGILE*. IMNSO: Much better to do something like: COMPUTE HighEnd=ANY(VAR2,"APP37","APP35","APP00","APP2R","APP03") AND RANGE(VAR1,2002,2009). VALUE LABELS Highend 0 "NO" 1 "YES". Also, get rid of those pesky (unnecessary) EXECUTE statements. Use variable names which make sense (product, year, status etc). HTH, David
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Thanks, David, for the caveats on Autorecode along with the streamlined
syntax and tips. It may take more time upfront coding strings as strings but you raise excellent points in that once done it'll be easy to replicate the syntax. Plus, as you further noted, it serves as a "check" for addressing instances of different coding schemes in subsequent data sets. (This is a strong possibility as I'm working with data from multiple sources.) I can use the coded info for other data manipulation so have decided for this situation to do the work by manual recoding instead of going the Autorecode route. As for your very informative "IMNSO" response, TYVM! :) elle -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso Sent: Friday, October 28, 2011 1:26 PM To: [hidden email] Subject: Re: Create a dichotomous variable based on condition(s) Elle, I would *NOT* bother with AUTORECODE in such a case!! What happens when you add other data and the codes are *NOT* the exactly same? You then need to track down the appropriate codes and rewrite the relevant syntax. Sometimes strings are *EASIER* than dealing with numerics (if that is how your data arrive). In other words, the current approach is *FRAGILE*. IMNSO: Much better to do something like: COMPUTE HighEnd=ANY(VAR2,"APP37","APP35","APP00","APP2R","APP03") AND RANGE(VAR1,2002,2009). VALUE LABELS Highend 0 "NO" 1 "YES". Also, get rid of those pesky (unnecessary) EXECUTE statements. Use variable names which make sense (product, year, status etc). HTH, David elle lists wrote: > > Thank you, Bruce Weaver, John Hall, Carlos Renato, and Melissa Ives, > for responding to my question. > > > > My apologies for posting the example which showed cases 16 and 19 > incorrectly flagged as YES (should have been NO) - the corrected table > is posted below. Thanks to Melissa Ives for the first posting with an > untested syntax. Running the syntax, however, generated an error (per > Carlo's > observation) which seems to have been related to the string variable. > John > Hall's observation about converting the string to numeric (Automatic > Recode) > helped to clear the path towards concocting a syntax. (The string > variable is one of several in this data set but I now see how much > easier it is to convert and work with a numeric format.) > > > > I was able to concoct a very beginner's "sad-but-works" syntax (below) > so Bruce Weaver's solution/summary is very welcome (!) and informative > (!) instruction on the process. His solution is reposted here: > > > >>As John F suggested, you could begin by using AUTORECODE to get a >>numeric > version of your VAR2. >Then, you want something like: > > > >>compute #cond1 = any(NumericVar2,value1,value2,value3, ..., valueX). > >>compute #cond2 = range(VAR1,2002,2009). > >>compute var3 = #cond1 AND #cond2. > >>formats var3 (f1.0). > >>value labels var3 1 'Yes' 0 'No'. > > > > > > Thanks to all for taking the time and interest. > > > > elle > > > > > > > CORRECTED EXAMPLE > > > ID > > VAR1 > > VAR2 > > VAR3 > > > 1 > > APP50C > > NO > > > 2 > > NO > > > 3 > > 2008 > > APP37 > > YES > > > 4 > > APP28T > > NO > > > 5 > > NO > > > 6 > > 2008 > > APP35 > > YES > > > 7 > > NO > > > 8 > > NO > > > 9 > > 2003 > > APP00 > > YES > > > 10 > > 2004 > > APP00 > > YES > > > 11 > > 2008 > > APP2R > > YES > > > 12 > > NO > > > 13 > > NO > > > 14 > > NO > > > 15 > > NO > > > 16 > > APP50C > > NO > > > 17 > > 2008 > > APP03 > > YES > > > 18 > > APP24X > > NO > > > 19 > > 2004 > > APP00 > > NO > > > > > > > > My torturous syntax/procedure: > > > > 1.Autocode the string variable (VAR2) to a numeric variable (VAR2num). > (var2num has values 1-9; blank cells/no product purchase is identified > as > "1".) > > AUTORECODE VARIABLES=VAR2 > > /INTO var2num > > /PRINT. > > > > 2.Converting 4-digit year (VAR1) to a single-digit variable > (var1b)equaling "1". > > RECODE VAR1 (2008=1) (2004=1) (2003=1) INTO var1b. > > EXECUTE. > > > > 3. Adding var2num with var1b. (To identify values that are either 1 > or > >1). > COMPUTE VAR3=VAR1b + var2num. > > EXECUTE. > > > > 4. Recoding VAR3 where values: > 1 is converted to "1" else =0. > > RECODE VAR3 (2=1) (3=1) (4=1) (5=1) (6=1) (7=1) (8=1) (9=1) (ELSE=0) > INTO VAR4. > > EXECUTE. > > VALUE LABELS 1='yes' 0='n. > > EXECUTE. > > > > > > > > -----Original Message----- > From: SPSSX(r) Discussion [mailto:SPSSX-L@.UGA] On Behalf Of Bruce > Weaver > Sent: Friday, October 28, 2011 10:55 AM > To: SPSSX-L@.UGA > Subject: Re: Create a dichotomous variable based on condition(s) > > > > The example you show below does not make it clear (to me, at least) > what the rule is. E.g., you have some cases flagged YES despite > having no data for Year (VAR1). That doesn't make sense, given what > you've said. > > > > As John F suggested, you could begin by using AUTORECODE to get a > numeric version of your VAR2. Then, you want something like: > > > > compute #cond1 = any(NumericVar2,value1,value2,value3, ..., valueX). > > compute #cond2 = range(VAR1,2002,2009). > > compute var3 = #cond1 AND #cond2. > > formats var3 (f1.0). > > value labels var3 1 'Yes' 0 'No'. > > > > > > In the first COMPUTE line above: > > NumericVar2 is a numeric version of your Var2, obtained via > AUTORECODE; value1, value2, etc are the values of NumericVar2 that are > your "certain higher-end products". > > > > HTH. > > > > > > elle lists wrote: > >> > >> Hi all, > >> > >> > >> > >> Would appreciate your help again. I'm trying to create a dichotomous > >> variable to categorize cases where people bought a certain "higher-end" > >> product (var2 which is a string) in a particular year (between 2002 >> to > >> 2009) > >> . If the two conditions are met, the case would be marked YES. If > >> either var1 and/or var2 are "blank" then the case is marked NO; and >> if > >> var2 > >> isn't a "higher-end" product, the case would also be marked NO. > >> (There are no cases listing a year but no product.) > >> > >> > >> > >> Thanks very much for your help. > >> > >> > >> > >> elle > -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Create-a-dichotomous-variable- based-on-condition-s-tp4947080p4947579.html Sent from the SPSSX Discussion mailing list archive at Nabble.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 ===================== 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 |
Administrator
|
In reply to this post by David Marso
Good arguments for omitting the AUTORECODE, David. I think I might throw in an UPCASE, though. And maybe LTRIM and RTRIM just to be safe. How about:
COMPUTE VAR2 = UPCASE(RTRIM(LTRIM(VAR2))). COMPUTE HighEnd=ANY(VAR2,"APP37","APP35","APP00","APP2R","APP03") AND RANGE(VAR1,2002,2009). VALUE LABELS Highend 0 "NO" 1 "YES".
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
In reply to this post by David Marso
Bear in mind that autorecode includes the
option of preserving the recode for future use and even updating it if
new entries appear. So it really isn't any more fragile than coding
the actual strings in the COMPUTE syntax. In fact, it makes it easier
to identify new or changed entries.
Jon Peck (no "h") Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: David Marso <[hidden email]> To: [hidden email] Date: 10/28/2011 05:30 PM Subject: Re: [SPSSX-L] Create a dichotomous variable based on condition(s) Sent by: "SPSSX(r) Discussion" <[hidden email]> Elle, I would *NOT* bother with AUTORECODE in such a case!! What happens when you add other data and the codes are *NOT* the exactly same? You then need to track down the appropriate codes and rewrite the relevant syntax. Sometimes strings are *EASIER* than dealing with numerics (if that is how your data arrive). In other words, the current approach is *FRAGILE*. IMNSO: Much better to do something like: COMPUTE HighEnd=ANY(VAR2,"APP37","APP35","APP00","APP2R","APP03") AND RANGE(VAR1,2002,2009). VALUE LABELS Highend 0 "NO" 1 "YES". Also, get rid of those pesky (unnecessary) EXECUTE statements. Use variable names which make sense (product, year, status etc). HTH, David elle lists wrote: > > Thank you, Bruce Weaver, John Hall, Carlos Renato, and Melissa Ives, for > responding to my question. > > > > My apologies for posting the example which showed cases 16 and 19 > incorrectly flagged as YES (should have been NO) - the corrected table is > posted below. Thanks to Melissa Ives for the first posting with an > untested > syntax. Running the syntax, however, generated an error (per Carlo's > observation) which seems to have been related to the string variable. > John > Hall's observation about converting the string to numeric (Automatic > Recode) > helped to clear the path towards concocting a syntax. (The string > variable > is one of several in this data set but I now see how much easier it is to > convert and work with a numeric format.) > > > > I was able to concoct a very beginner's "sad-but-works" syntax (below) so > Bruce Weaver's solution/summary is very welcome (!) and informative (!) > instruction on the process. His solution is reposted here: > > > >>As John F suggested, you could begin by using AUTORECODE to get a numeric > version of your VAR2. >Then, you want something like: > > > >>compute #cond1 = any(NumericVar2,value1,value2,value3, ..., valueX). > >>compute #cond2 = range(VAR1,2002,2009). > >>compute var3 = #cond1 AND #cond2. > >>formats var3 (f1.0). > >>value labels var3 1 'Yes' 0 'No'. > > > > > > Thanks to all for taking the time and interest. > > > > elle > > > > > > > CORRECTED EXAMPLE > > > ID > > VAR1 > > VAR2 > > VAR3 > > > 1 > > APP50C > > NO > > > 2 > > NO > > > 3 > > 2008 > > APP37 > > YES > > > 4 > > APP28T > > NO > > > 5 > > NO > > > 6 > > 2008 > > APP35 > > YES > > > 7 > > NO > > > 8 > > NO > > > 9 > > 2003 > > APP00 > > YES > > > 10 > > 2004 > > APP00 > > YES > > > 11 > > 2008 > > APP2R > > YES > > > 12 > > NO > > > 13 > > NO > > > 14 > > NO > > > 15 > > NO > > > 16 > > APP50C > > NO > > > 17 > > 2008 > > APP03 > > YES > > > 18 > > APP24X > > NO > > > 19 > > 2004 > > APP00 > > NO > > > > > > > > My torturous syntax/procedure: > > > > 1.Autocode the string variable (VAR2) to a numeric variable (VAR2num). > (var2num has values 1-9; blank cells/no product purchase is identified as > "1".) > > AUTORECODE VARIABLES=VAR2 > > /INTO var2num > > /PRINT. > > > > 2.Converting 4-digit year (VAR1) to a single-digit variable > (var1b)equaling > "1". > > RECODE VAR1 (2008=1) (2004=1) (2003=1) INTO var1b. > > EXECUTE. > > > > 3. Adding var2num with var1b. (To identify values that are either 1 or > >1). > COMPUTE VAR3=VAR1b + var2num. > > EXECUTE. > > > > 4. Recoding VAR3 where values: > 1 is converted to "1" else =0. > > RECODE VAR3 (2=1) (3=1) (4=1) (5=1) (6=1) (7=1) (8=1) (9=1) (ELSE=0) INTO > VAR4. > > EXECUTE. > > VALUE LABELS 1='yes' 0='n. > > EXECUTE. > > > > > > > > -----Original Message----- > From: SPSSX(r) Discussion [[hidden email]] On Behalf Of > Bruce Weaver > Sent: Friday, October 28, 2011 10:55 AM > To: SPSSX-L@.UGA > Subject: Re: Create a dichotomous variable based on condition(s) > > > > The example you show below does not make it clear (to me, at least) what > the > rule is. E.g., you have some cases flagged YES despite having no data for > Year (VAR1). That doesn't make sense, given what you've said. > > > > As John F suggested, you could begin by using AUTORECODE to get a numeric > version of your VAR2. Then, you want something like: > > > > compute #cond1 = any(NumericVar2,value1,value2,value3, ..., valueX). > > compute #cond2 = range(VAR1,2002,2009). > > compute var3 = #cond1 AND #cond2. > > formats var3 (f1.0). > > value labels var3 1 'Yes' 0 'No'. > > > > > > In the first COMPUTE line above: > > NumericVar2 is a numeric version of your Var2, obtained via AUTORECODE; > value1, value2, etc are the values of NumericVar2 that are your "certain > higher-end products". > > > > HTH. > > > > > > elle lists wrote: > >> > >> Hi all, > >> > >> > >> > >> Would appreciate your help again. I'm trying to create a dichotomous > >> variable to categorize cases where people bought a certain "higher-end" > >> product (var2 which is a string) in a particular year (between 2002 to > >> 2009) > >> . If the two conditions are met, the case would be marked YES. If > >> either var1 and/or var2 are "blank" then the case is marked NO; and if > >> var2 > >> isn't a "higher-end" product, the case would also be marked NO. > >> (There are no cases listing a year but no product.) > >> > >> > >> > >> Thanks very much for your help. > >> > >> > >> > >> elle > -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Create-a-dichotomous-variable-based-on-condition-s-tp4947080p4947579.html Sent from the SPSSX Discussion mailing list archive at Nabble.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 |
In reply to this post by Donna Carroll
This means that at least one character
code appeared in the input but does not have a character code in your current
locale and mode. I can't tell from the text below what it is, but
I noticed that the last two value label statements have some curly quotation
marks rather than the usual ascii straight quotes.
If you turn on Unicode mode, you should be able to read all the characters properly - Excel text is Unicode. You can switch to Unicode mode via Edit>Options or by running SET UNICODE ON. (Read about this in the Options help to see all the implications.) You can only switch Unicode on or off when no dataset is open. Jon Peck (no "h") Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: Donna Carroll <[hidden email]> To: [hidden email] Date: 10/28/2011 05:54 PM Subject: [SPSSX-L] Message: "Text value unmappable in the current server locale" Sent by: "SPSSX(r) Discussion" <[hidden email]> I'm new to this... What to do? Coding something very routine -- Value Labels -- and for the first time ever... Received an error message: "Text value unmappable in the current server locale" I tried starting over; that is, opening an Excel file, saving it as spss data file; opening new sytax VALUE LABELS Q21 1 "No" 2 "Part time" 3 "Full time" 0 “NR”. VALUE LABELS Q22 1 "<3 months" 2 ">3 months but<6 months" 3 ">6 months but <12 months" 4 ">12 months but <2 years" 5 "2 years or more" 0 “NR”. VALUE LABELS Q23 1 "Business" 2 "Communications" 3 "Education" 4 "Finance" 5 "Information Technology" 6 "Insurance" 7 "Manufacturing" 8 "Medical" 9 "Nonprofit" 10 "Retail" 0 “NR”. VALUE LABELS Q24 1 "Transgender" 2 "Male" 3 "Female" 0 “NR”. VALUE LABELS Q25 1 "No" 2 "Yes" 0 “NR”. VALUE LABELS Q26 1 "Asian" 2 "Black or African American" 3 "American Indian or Alaska Native" 4 "White" 5 "Other" 0 “NR”. VALUE LABELS Q27 1 "18 to 30" 2 "31 to 50" 3 "51 to 65" 4 "over 65" 0 “NR”. VALUE LABELS Q28 1 "Protestant" 2 "Catholic" 3 "Mormon" 4 "Orthodox" 5 "Jewish" 6 "Muslim" 7 "Buddhist" 8 "Hindu" 9 "Atheist" 10 "Agnostic" 11 “Other” 12 “None” 0 “NR”. VALUE LABELS Q29 1 "No" 2 "Yes" 0 “NR”. Each variable, for which I am trying to create value labels,
is a transformed variable. For example: COMPUTE Q21= (V2*2)
+ (V3*3) + (V4*1).
|
In reply to this post by Jon K Peck
Jon, thanks for the interesting info. It sounds like there’s a command or feature to “…preserve the recode for future use and even update” it. Is this available in version 19/20? If so, where may I check this out? Thanks for the help. elle From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jon K Peck Bear in mind that autorecode includes the option of preserving the recode for future use and even updating it if new entries appear. So it really isn't any more fragile than coding the actual strings in the COMPUTE syntax. In fact, it makes it easier to identify new or changed entries.
|
This was introduced back around version
14 IIRC (I was involved in the design). In the autorecode dialog,
you would first check "Save template as" and then later use Apply
template from and optionally update the template.
The Viewer output displays the mapping, and new values will be at the end. And, from the syntax help, • If APPLY TEMPLATE and SAVE TEMPLATE are both used in the same AUTORECODE command, APPLY TEMPLATE is always processed first, regardless of subcommand order, and the autorecode scheme saved by SAVE TEMPLATE is the union of the original template plus any appended value definitions. • APPLY TEMPLATE and SAVE TEMPLATE can specify the same file, resulting in the template being updated to include any newly appended value definitions. HTH,
Jon, thanks for the interesting info. It sounds like there’s a command or feature to “…preserve the recode for future use and even update” it. Is this available in version 19/20? If so, where may I check this out? Thanks for the help. elle From: SPSSX(r) Discussion [[hidden email]] On Behalf Of Jon K Peck Sent: Friday, October 28, 2011 3:43 PM To: [hidden email] Subject: Re: Create a dichotomous variable based on condition(s) Bear in mind that autorecode includes the option of preserving the recode for future use and even updating it if new entries appear. So it really isn't any more fragile than coding the actual strings in the COMPUTE syntax. In fact, it makes it easier to identify new or changed entries. Jon Peck (no "h") Senior Software Engineer, IBM peck@... new phone: 720-342-5621 From: David Marso <david.marso@...> To: [hidden email] Date: 10/28/2011 05:30 PM Subject: Re: [SPSSX-L] Create a dichotomous variable based on condition(s) Sent by: "SPSSX(r) Discussion" <[hidden email]> Elle, I would *NOT* bother with AUTORECODE in such a case!! What happens when you add other data and the codes are *NOT* the exactly same? You then need to track down the appropriate codes and rewrite the relevant syntax. Sometimes strings are *EASIER* than dealing with numerics (if that is how your data arrive). In other words, the current approach is *FRAGILE*. IMNSO: Much better to do something like: COMPUTE HighEnd=ANY(VAR2,"APP37","APP35","APP00","APP2R","APP03") AND RANGE(VAR1,2002,2009). VALUE LABELS Highend 0 "NO" 1 "YES". Also, get rid of those pesky (unnecessary) EXECUTE statements. Use variable names which make sense (product, year, status etc). HTH, David elle lists wrote: > > Thank you, Bruce Weaver, John Hall, Carlos Renato, and Melissa Ives, for > responding to my question. > > > > My apologies for posting the example which showed cases 16 and 19 > incorrectly flagged as YES (should have been NO) - the corrected table is > posted below. Thanks to Melissa Ives for the first posting with an > untested > syntax. Running the syntax, however, generated an error (per Carlo's > observation) which seems to have been related to the string variable. > John > Hall's observation about converting the string to numeric (Automatic > Recode) > helped to clear the path towards concocting a syntax. (The string > variable > is one of several in this data set but I now see how much easier it is to > convert and work with a numeric format.) > > > > I was able to concoct a very beginner's "sad-but-works" syntax (below) so > Bruce Weaver's solution/summary is very welcome (!) and informative (!) > instruction on the process. His solution is reposted here: > > > >>As John F suggested, you could begin by using AUTORECODE to get a numeric > version of your VAR2. >Then, you want something like: > > > >>compute #cond1 = any(NumericVar2,value1,value2,value3, ..., valueX). > >>compute #cond2 = range(VAR1,2002,2009). > >>compute var3 = #cond1 AND #cond2. > >>formats var3 (f1.0). > >>value labels var3 1 'Yes' 0 'No'. > > > > > > Thanks to all for taking the time and interest. > > > > elle > > > > > > > CORRECTED EXAMPLE > > > ID > > VAR1 > > VAR2 > > VAR3 > > > 1 > > APP50C > > NO > > > 2 > > NO > > > 3 > > 2008 > > APP37 > > YES > > > 4 > > APP28T > > NO > > > 5 > > NO > > > 6 > > 2008 > > APP35 > > YES > > > 7 > > NO > > > 8 > > NO > > > 9 > > 2003 > > APP00 > > YES > > > 10 > > 2004 > > APP00 > > YES > > > 11 > > 2008 > > APP2R > > YES > > > 12 > > NO > > > 13 > > NO > > > 14 > > NO > > > 15 > > NO > > > 16 > > APP50C > > NO > > > 17 > > 2008 > > APP03 > > YES > > > 18 > > APP24X > > NO > > > 19 > > 2004 > > APP00 > > NO > > > > > > > > My torturous syntax/procedure: > > > > 1.Autocode the string variable (VAR2) to a numeric variable (VAR2num). > (var2num has values 1-9; blank cells/no product purchase is identified as > "1".) > > AUTORECODE VARIABLES=VAR2 > > /INTO var2num > > /PRINT. > > > > 2.Converting 4-digit year (VAR1) to a single-digit variable > (var1b)equaling > "1". > > RECODE VAR1 (2008=1) (2004=1) (2003=1) INTO var1b. > > EXECUTE. > > > > 3. Adding var2num with var1b. (To identify values that are either 1 or > >1). > COMPUTE VAR3=VAR1b + var2num. > > EXECUTE. > > > > 4. Recoding VAR3 where values: > 1 is converted to "1" else =0. > > RECODE VAR3 (2=1) (3=1) (4=1) (5=1) (6=1) (7=1) (8=1) (9=1) (ELSE=0) INTO > VAR4. > > EXECUTE. > > VALUE LABELS 1='yes' 0='n. > > EXECUTE. > > > > > > > > -----Original Message----- > From: SPSSX(r) Discussion [[hidden email]] On Behalf Of > Bruce Weaver > Sent: Friday, October 28, 2011 10:55 AM > To: [hidden email] > Subject: Re: Create a dichotomous variable based on condition(s) > > > > The example you show below does not make it clear (to me, at least) what > the > rule is. E.g., you have some cases flagged YES despite having no data for > Year (VAR1). That doesn't make sense, given what you've said. > > > > As John F suggested, you could begin by using AUTORECODE to get a numeric > version of your VAR2. Then, you want something like: > > > > compute #cond1 = any(NumericVar2,value1,value2,value3, ..., valueX). > > compute #cond2 = range(VAR1,2002,2009). > > compute var3 = #cond1 AND #cond2. > > formats var3 (f1.0). > > value labels var3 1 'Yes' 0 'No'. > > > > > > In the first COMPUTE line above: > > NumericVar2 is a numeric version of your Var2, obtained via AUTORECODE; > value1, value2, etc are the values of NumericVar2 that are your "certain > higher-end products". > > > > HTH. > > > > > > elle lists wrote: > >> > >> Hi all, > >> > >> > >> > >> Would appreciate your help again. I'm trying to create a dichotomous > >> variable to categorize cases where people bought a certain "higher-end" > >> product (var2 which is a string) in a particular year (between 2002 to > >> 2009) > >> . If the two conditions are met, the case would be marked YES. If > >> either var1 and/or var2 are "blank" then the case is marked NO; and if > >> var2 > >> isn't a "higher-end" product, the case would also be marked NO. > >> (There are no cases listing a year but no product.) > >> > >> > >> > >> Thanks very much for your help. > >> > >> > >> > >> elle > -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Create-a-dichotomous-variable-based-on-condition-s-tp4947080p4947579.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@... (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 |