Hello all,
Does anyone know of a way to create a new variable and populate it with values according to the rows of another variable (not values)? If it's writing syntax, how do you do it? Any help much appreciated. Thanks, Tom -- Thomas Stieve Social Sciences Data Librarian Brown University Box A Providence, RI 02912 Tel: 401.863.7978 |
At 09:55 AM 11/12/2010, Stieve, Thomas wrote:
>Does anyone know of a way to create a new variable and populate it >with values according to the rows of another variable (not values)? Can you explain more, and give an example, what you mean by "populating [a variable] with values according to the rows of another variable"? ===================== 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 Stieve, Thomas
Hi,
I'm sorry if I've been vague. I have a student who has a variable with thousands of school names. It's a string variable, and each case is unique. He wants to create a second variable with 3 values (1 elementary school, 2 middle school, 3 high school). They are sorted as the elementary cases are first, middle schools are second, high are third. So, we need to create a second variable where rows 1 - 20 are 1s, 21 - 40 are 2s, etc. Any suggestions? I hope I explained that better. Tom On Fri, Nov 12, 2010 at 8:55 AM, Stieve, Thomas <[hidden email]> wrote: Hello all, -- Thomas Stieve Social Sciences Data Librarian Brown University Box A Providence, RI 02912 Tel: 401.863.7978 |
At 04:04 PM 11/12/2010, Stieve, Thomas wrote:
>I have a student who has a variable with thousands of school >names. It's a string variable, and each case is unique. He wants >to create a second variable with 3 values (1 elementary school, 2 >middle school, 3 high school). They are sorted as the elementary >cases are first, middle schools are second, high are third. So, we >need to create a second variable where rows 1 - 20 are 1s, 21 - 40 are 2s, etc. This should work (untested), though it's bad practice in one way: the row counts are 'data in code', and if you don't get them right, you'll get wrong values in your output, with no warning. NUMERIC SchoolType (F2). VAL LABELS SchoolType 1 'Elementary' 2 'Middle school' 3 'High school'. RECODE $CASENUM (01 THRU 20 = 1) (21 THRU 40 = 2) (40 THRU HI = 3) INTO SchoolType. ===================== 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 Stieve, Thomas
It sounds as if ranges of case numbers are all you have to identify the various school types. If that is correct, then something like this should work. I used the same numbers as in your brief example, but obviously they will need to be changed if you have thousands of school names. do if range($casenum,1,20). - compute schooltype = 1. else if range($casenum,21,40). - compute schooltype = 2. else if range($casenum,41,60). - compute schooltype = 3. end if. value labels schooltype 1 'Elementary school' 2 'Middle school' 3 'High school' . 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 Stieve, Thomas
CONTENTS DELETED
The author has deleted this message.
|
Administrator
|
In reply to this post by Stieve, Thomas
"Any suggestions? I hope I explained that better."
My ESP is still not kicking in... How is it that "thousands of school names." are to map to rows 1-20, 20-40 etc?
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?" |
In reply to this post by Stieve, Thomas
Since you are at Brown, it is likely that you are discussing schools
in the USA. If you are not, ignore this post.
One approach is to use the index string function. something like this data list list/ name (A40). begin data. "Middle Falls High School" "High Point Middle schoo" "joes highschool' "St.mary's Grammar school" "abc primay schoo' "bcd elem school' "def high school" "middlesex elementary school" "middlesex high school" end data. compute haselem = index(upcase(name), "ELEM") gt 0. compute hasmidl = index(upcase(name), "MIDDLE") gt 0. compute hashigh = index(upcase(name), "HIGH") gt 0. crosstabs tables= haselem by hasmidl by hashigh. ALSO depending on the jurisdiction(s) you are working in, not all schools fall neatly into those categories. some are k-12, some are {k-3, 4-6, 7-9, 10-12}, some are {K-8, 9-12} etc. Do you have other information such as address, zip, etc? Another approach is to download the Common Core of data http://nces.ed.gov/ccd/ Then match it with the information you already have. To find public and private schools that did not have a match go to http://nces.ed.gov/globallocator/ How large the files are would depend on what schools you are working with? A national probability sample? A single state? A region? A few districts? etc. You may even find existing data fields that would be useful in you current study. I do not recall whether the longitude & latitude are yet fully populated in the current editions. In old versions of SPSS before they dropped the ability to do mapping that could be useful for some purposes. Some free mapping capabilities are at http://www.healthlandscape.org/index.cfm?focus=CommunityHealthData In the future it is often handy to start with the NCES school id, and use that as the case identifier in the beginning of the job. That gives you the opportunity to match to existing data on the schools. Many school specific data can be found that have NCES school ids as fields.This is very much the same thing as always using the Federal Information Processing Standards Codes (FIPS Codes) for jurisdictions. Art Kendall Social Research Consultants On 11/12/2010 3:04 PM, Stieve, Thomas wrote: Hi,===================== 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 |
Administrator
|
In reply to this post by Stieve, Thomas
Since the cases are ordered by elementary, middle, high schools.
Create a new column in the data editor (col2). Put a 1 in the first case of col2 (elementary) scroll to your first instance of 'middle school' , enter a 2 in col2. scroll to first instance of 'high school', enter a 3 in col2. In syntax editor. IF MISSING(col2) col2=LAG(col2). FREQ col2. run the above lines. DONE.
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?" |
Free forum by Nabble | Edit this page |