Recoding Question

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Recoding Question

Craig Johnson
I'm currently running a bunch of analyses across several studies.  To
accomplish what I need to I calculate a variable, recode a variable,
add 132 value labels on each of the datasets, convert the value labels
to strings, and then transpose things so cases become variables.  (It
is some what complicated to explain so won't get into it much…but the
jist is I'm using OMS to export data, manipulating it so I can run
analyses on it and then merging a bunch of results together.)  I have
created syntax to do this for each data set and everything works well.
 I have also set up a secondary syntax that uses an Include statement
for each of the other syntax files I have created to relabel each data
set.  By doing this I can use nested syntax files and use a single
file to call all 42 of the other syntax files I need run to relabel a
variable.

Currently I can run each single syntax file independently and it adds
values labels properly.  However when I try and run this in the
"batch" syntax file, which calls the other syntax files, I get an
error for the value labels.  So……just to be clear…it runs fine if I
run them individually but when I try and run them all through a single
file with include statements I get errors on the value labels…  I
believe this may be a function of SPSS being sensitive to how things
are configured when running nested syntax files.  I was wondering if
anyone has some insight into what might be wrong.  Below is a copy of
how the value labels is set up….any help would be appreciated.

Value Labels New
101  'Value 1'
102  'Value 2'
103  'Value 3'
104  'Value 4'
105  'Value 5'
106  'Value 6'
107  'Value 7'
108  'Value 8'
109  'Value 9'
110  'Value 10'
111  'Value 11'
112  'Value 12'
113  'Value 13'
114  'Value 14'
115  'Value 15'.
Reply | Threaded
Open this post in threaded view
|

Re: Recoding Question

ViAnn Beadle
I'm not sure why you're going through value labels to create strings but you
can create the string directly from your numeric variable. Let's assume, in
the simple case, I have a numeric variable call numvalue taking on values 1
through 10. Then

string newstring (a8).
compute newstring =concat("Value ", string(numvalue - 100,f3)).

This will produce a new string variable with values like Value 1. What is
important here, based upon your earlier post is that the first argument to
numvalue is any numeric expression so you could have something like
string(numvalue-1 * 10 + 139, f3). Note that the second argument to the
string function is the numeric format to use when composing the string.

Without seeing the actual error message and the syntax run it's really hard
to diagnose why your master include is not working. Note that the INCLUDE
command requires that all commands start in column 1 and that any
continuations to the commands NOT start in column 1 so if you have syntax
like that below within a file named on the INCLUDE command, it will generate
an error. Use the INSERT command instead.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Craig Johnson
Sent: Thursday, September 20, 2007 7:24 PM
To: [hidden email]
Subject: Recoding Question

I'm currently running a bunch of analyses across several studies.  To
accomplish what I need to I calculate a variable, recode a variable,
add 132 value labels on each of the datasets, convert the value labels
to strings, and then transpose things so cases become variables.  (It
is some what complicated to explain so won't get into it much.but the
jist is I'm using OMS to export data, manipulating it so I can run
analyses on it and then merging a bunch of results together.)  I have
created syntax to do this for each data set and everything works well.
 I have also set up a secondary syntax that uses an Include statement
for each of the other syntax files I have created to relabel each data
set.  By doing this I can use nested syntax files and use a single
file to call all 42 of the other syntax files I need run to relabel a
variable.

Currently I can run each single syntax file independently and it adds
values labels properly.  However when I try and run this in the
"batch" syntax file, which calls the other syntax files, I get an
error for the value labels.  So..just to be clear.it runs fine if I
run them individually but when I try and run them all through a single
file with include statements I get errors on the value labels.  I
believe this may be a function of SPSS being sensitive to how things
are configured when running nested syntax files.  I was wondering if
anyone has some insight into what might be wrong.  Below is a copy of
how the value labels is set up..any help would be appreciated.

Value Labels New
101  'Value 1'
102  'Value 2'
103  'Value 3'
104  'Value 4'
105  'Value 5'
106  'Value 6'
107  'Value 7'
108  'Value 8'
109  'Value 9'
110  'Value 10'
111  'Value 11'
112  'Value 12'
113  'Value 13'
114  'Value 14'
115  'Value 15'.
Reply | Threaded
Open this post in threaded view
|

Re: Recoding Question

Craig Johnson
Hum...maybe the insert is a better way to go then.  I'll give that a
shot when I get into work in the morning.

For what it's worth the reason I'm using the value labels to strings
is because I'm basically running correlations to use for a
meta-analysis.  To make it easier on myself I'm setting it up to use
OMS to export the correlation tables to a new SPSS file.  I then open
that SPSS file and manipulate the data into the format Sample Size 1,
Correlation 1, Sample Size 2, Correlation 2....etc.  The problem is
that when you open the OMS created data file is that things aren't
listed in the proper case format they need to have a case to variable
transformation.  To further complicate the issue the you can't just
transpose things because Variable2 has the actual variable name you
need to transpose exactly the same three times.  IE you run a
correlation and get MoneySpent, MoneySpent, MoneySpent, in one
Variable from case 1 to case 3.  In Variable 2 you get Signficance, N,
Correlation.  If you notice you can't transpose because you'll end up
with three "MoneySpent's."  To get around it and in the proper format
I use an automatic recode for the Correlation, Significance Test,
Sample size as well as the variable name.  I then recode the
Correlation, Significance Test into the same variable changing the
default values of 1-3 into 100-300.  Once they all have unique
identifiers I can label them all and have no duplicate cases.  I then
take those unique identifiers and create a string variable so I can
transpose the data in a case to variable fashion and have correct
label names. Clear as mud eh? =)

It is just this darn add value labels snag that has me hung up.....



On 9/20/07, ViAnn Beadle <[hidden email]> wrote:

> I'm not sure why you're going through value labels to create strings but you
> can create the string directly from your numeric variable. Let's assume, in
> the simple case, I have a numeric variable call numvalue taking on values 1
> through 10. Then
>
> string newstring (a8).
> compute newstring =concat("Value ", string(numvalue - 100,f3)).
>
> This will produce a new string variable with values like Value 1. What is
> important here, based upon your earlier post is that the first argument to
> numvalue is any numeric expression so you could have something like
> string(numvalue-1 * 10 + 139, f3). Note that the second argument to the
> string function is the numeric format to use when composing the string.
>
> Without seeing the actual error message and the syntax run it's really hard
> to diagnose why your master include is not working. Note that the INCLUDE
> command requires that all commands start in column 1 and that any
> continuations to the commands NOT start in column 1 so if you have syntax
> like that below within a file named on the INCLUDE command, it will generate
> an error. Use the INSERT command instead.
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
> Craig Johnson
> Sent: Thursday, September 20, 2007 7:24 PM
> To: [hidden email]
> Subject: Recoding Question
>
> I'm currently running a bunch of analyses across several studies.  To
> accomplish what I need to I calculate a variable, recode a variable,
> add 132 value labels on each of the datasets, convert the value labels
> to strings, and then transpose things so cases become variables.  (It
> is some what complicated to explain so won't get into it much.but the
> jist is I'm using OMS to export data, manipulating it so I can run
> analyses on it and then merging a bunch of results together.)  I have
> created syntax to do this for each data set and everything works well.
>  I have also set up a secondary syntax that uses an Include statement
> for each of the other syntax files I have created to relabel each data
> set.  By doing this I can use nested syntax files and use a single
> file to call all 42 of the other syntax files I need run to relabel a
> variable.
>
> Currently I can run each single syntax file independently and it adds
> values labels properly.  However when I try and run this in the
> "batch" syntax file, which calls the other syntax files, I get an
> error for the value labels.  So..just to be clear.it runs fine if I
> run them individually but when I try and run them all through a single
> file with include statements I get errors on the value labels.  I
> believe this may be a function of SPSS being sensitive to how things
> are configured when running nested syntax files.  I was wondering if
> anyone has some insight into what might be wrong.  Below is a copy of
> how the value labels is set up..any help would be appreciated.
>
> Value Labels New
> 101  'Value 1'
> 102  'Value 2'
> 103  'Value 3'
> 104  'Value 4'
> 105  'Value 5'
> 106  'Value 6'
> 107  'Value 7'
> 108  'Value 8'
> 109  'Value 9'
> 110  'Value 10'
> 111  'Value 11'
> 112  'Value 12'
> 113  'Value 13'
> 114  'Value 14'
> 115  'Value 15'.
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Recoding Question

Peck, Jon
I'm not following all the intricacies of this discussion, but here are a few general ideas that might help.

- You can pivot your output using OMS by using the COLUMNS subcommand, which may put the data in a more convenient form
- Have you considered using APPLY DICTIONARY to copy value labels from one dataset to another?  If you create an SAV file with the labels you want already defined, you can just apply those to new or existing variables (of the same type)
- If you need a lot of logic for this beyond what you can do with the regular SPSS tools, you can use Python programmability, which would let you work on the variable metadata quite conveniently.

HTH,
Jon Peck

p. s. ViAnn is quite right about INSERT vs INCLUDE.  Always use INSERT unless you have to work with an old batch-style syntax file.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Craig Johnson
Sent: Thursday, September 20, 2007 9:25 PM
To: [hidden email]
Subject: Re: [SPSSX-L] Recoding Question

Hum...maybe the insert is a better way to go then.  I'll give that a
shot when I get into work in the morning.

For what it's worth the reason I'm using the value labels to strings
is because I'm basically running correlations to use for a
meta-analysis.  To make it easier on myself I'm setting it up to use
OMS to export the correlation tables to a new SPSS file.  I then open
that SPSS file and manipulate the data into the format Sample Size 1,
Correlation 1, Sample Size 2, Correlation 2....etc.  The problem is
that when you open the OMS created data file is that things aren't
listed in the proper case format they need to have a case to variable
transformation.  To further complicate the issue the you can't just
transpose things because Variable2 has the actual variable name you
need to transpose exactly the same three times.  IE you run a
correlation and get MoneySpent, MoneySpent, MoneySpent, in one
Variable from case 1 to case 3.  In Variable 2 you get Signficance, N,
Correlation.  If you notice you can't transpose because you'll end up
with three "MoneySpent's."  To get around it and in the proper format
I use an automatic recode for the Correlation, Significance Test,
Sample size as well as the variable name.  I then recode the
Correlation, Significance Test into the same variable changing the
default values of 1-3 into 100-300.  Once they all have unique
identifiers I can label them all and have no duplicate cases.  I then
take those unique identifiers and create a string variable so I can
transpose the data in a case to variable fashion and have correct
label names. Clear as mud eh? =)

It is just this darn add value labels snag that has me hung up.....



On 9/20/07, ViAnn Beadle <[hidden email]> wrote:

> I'm not sure why you're going through value labels to create strings but you
> can create the string directly from your numeric variable. Let's assume, in
> the simple case, I have a numeric variable call numvalue taking on values 1
> through 10. Then
>
> string newstring (a8).
> compute newstring =concat("Value ", string(numvalue - 100,f3)).
>
> This will produce a new string variable with values like Value 1. What is
> important here, based upon your earlier post is that the first argument to
> numvalue is any numeric expression so you could have something like
> string(numvalue-1 * 10 + 139, f3). Note that the second argument to the
> string function is the numeric format to use when composing the string.
>
> Without seeing the actual error message and the syntax run it's really hard
> to diagnose why your master include is not working. Note that the INCLUDE
> command requires that all commands start in column 1 and that any
> continuations to the commands NOT start in column 1 so if you have syntax
> like that below within a file named on the INCLUDE command, it will generate
> an error. Use the INSERT command instead.
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
> Craig Johnson
> Sent: Thursday, September 20, 2007 7:24 PM
> To: [hidden email]
> Subject: Recoding Question
>
> I'm currently running a bunch of analyses across several studies.  To
> accomplish what I need to I calculate a variable, recode a variable,
> add 132 value labels on each of the datasets, convert the value labels
> to strings, and then transpose things so cases become variables.  (It
> is some what complicated to explain so won't get into it much.but the
> jist is I'm using OMS to export data, manipulating it so I can run
> analyses on it and then merging a bunch of results together.)  I have
> created syntax to do this for each data set and everything works well.
>  I have also set up a secondary syntax that uses an Include statement
> for each of the other syntax files I have created to relabel each data
> set.  By doing this I can use nested syntax files and use a single
> file to call all 42 of the other syntax files I need run to relabel a
> variable.
>
> Currently I can run each single syntax file independently and it adds
> values labels properly.  However when I try and run this in the
> "batch" syntax file, which calls the other syntax files, I get an
> error for the value labels.  So..just to be clear.it runs fine if I
> run them individually but when I try and run them all through a single
> file with include statements I get errors on the value labels.  I
> believe this may be a function of SPSS being sensitive to how things
> are configured when running nested syntax files.  I was wondering if
> anyone has some insight into what might be wrong.  Below is a copy of
> how the value labels is set up..any help would be appreciated.
>
> Value Labels New
> 101  'Value 1'
> 102  'Value 2'
> 103  'Value 3'
> 104  'Value 4'
> 105  'Value 5'
> 106  'Value 6'
> 107  'Value 7'
> 108  'Value 8'
> 109  'Value 9'
> 110  'Value 10'
> 111  'Value 11'
> 112  'Value 12'
> 113  'Value 13'
> 114  'Value 14'
> 115  'Value 15'.
>
>