|
Dear SPSS-L,
=====================
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
I have a data set in which three numeric variables need to be combined into one variable. The three variables look like this in the data set: x1 x2 x3 001 1 0 002 0 1 003 0 1 . . . . . . 500 1 1 Note that x1 has leading zeros for numbers less than 100 which must remain in the combined variable. The combined variable should look like this: x4 00110 00201 00301 . . 50011 Any help would be appreciated. Apologies if this has been discussed previously. Best, Ryan |
|
Administrator
|
Hi Ryan. I have no SPSS on this machine, so the following is untested. But I think it should do the trick. I assume your x1 is a numeric variable formatted as N3. (If not, this definitely won't work.)
COMPUTE x4 = SUM(x1*100, x2*10, x3). FORMATS x4 (N5). /* Keep leading zeros. * List first 5 cases to check. LIST VARIABLES= x1 to x4 /CASES=FROM 1 TO 5. Cheers, Bruce
--
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/). |
|
Hi Bruce.Worked like a charm. Thank you. -Ryan On Sat, Jan 16, 2016 at 2:23 PM, Bruce Weaver <[hidden email]> wrote: Hi Ryan. I have no SPSS on this machine, so the following is untested. But |
|
In reply to this post by Bruce Weaver
I sometimes find this type of concatenation troublesome, especially if there is missing data.
COMPUTE x4 = SUM(x1*100, x2*10, x3). will set missing data to 0 and evaluate the sum, whereas COMPUTE x4 = x1*100 + x2*10 + x3. will set x4 to missing if any term is missing. Hopefully x1 to x3 are mandatory input data and non-missing, otherwise used carefully ;-) /PRogman
|
|
Administrator
|
Yes, good catch. Alternatively, one could use SUM.3 to return missing if any components are missing.
COMPUTE x4 = SUM.3(x1*100, x2*10, x3). This has the advantage of being more explicit about what will happen if any component is missing. With the + signs, one is depending on the syntax user to know the rules! ;-)
--
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 Ryan
Ryan That’s a natty little trick often used for data management. Together with RECODE it can be a simple alternative to a series of IF or DO IF commands to create conditional combinations. For instance a social services client once wanted secondary analysis of their own local authority data from a regional health and lifestyle survey* to produce a new variable combining responsibility for children with marital status: freq v670 v715.
The new variable was generated by: compute famstat=v670*10+v715. recode famstat (21 24 25 26=1)(22 23=2)(11 14 15 16=3)(12 13=2)(else=sysmis). value labels famstat 1 'Single: no kids' 2 'Couple: no kids' 3 'Single: + kids' 4 'Couple: + kids'. freq var famstat. Et voilà!
. . which was then tabulated against a range of income, diet and health measures. The list has many instances of similar tricks of the trade. 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 * Griffiths S Unfair Shares: an investigation of the effects the Social Security Act in Islington Welfare Rights Unit, Islington 1989 From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Ryan Black Hi Bruce.Worked like a charm. Thank you. -Ryan On Sat, Jan 16, 2016 at 2:23 PM, Bruce Weaver <[hidden email]> wrote:
===================== 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 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Very clever, John! Thank you, and thanks to everybody who responded. -Ryan On Sun, Jan 17, 2016 at 1:30 AM, John F Hall <[hidden email]> wrote:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Free forum by Nabble | Edit this page |
