Hello List,
I am very pleased with the subcommands 'apply template' and 'save template' on the autorecode command - especially because the template can be applied and updated and re-saved all in the same command. I love it. However, what if I want to create a template that has numbers assigned to values in non-ordinal arrangements (like: 'Black' = 1, 'Asian' = 2, 'White' = 3, 'Intl' = 4). I can see many situations where having everything arranged alphabetically will make them out of the order I want them in when I try to create a table. Can I create a template that I can apply and update via autorecode that does not require my values to sorted to begin with? Thanks! Gary Moser Research Analyst Institutional Research Dominican University of California Ph: 415.482.2400 Fax:415.257.1367 Email: [hidden email] <mailto:[hidden email]> |
Hi, Gary!
At 02:18 PM 10/23/2006, Moser, Gary wrote: >I am very pleased with the subcommands 'apply template' and 'save >template' on the autorecode command. What if I want to create a >template that has numbers assigned to values in non-ordinal >arrangements? Can I create a template that I can apply and update via >autorecode that does not require my values to sorted to begin with? Boy, I sure thought so. For one, >at 01:28 PM 3/11/2006, Michael Healy <[hidden email]> wrote >("Re: Speeding up Recode"): > >>I use AUTORECODE with the APPLY TEMPLATE option. The template file >>turns out to be a standard SPSS data file. The manual states that >>creating your own files is experimental, but so far its working >>fine. This procedure is hundreds if not thousands of times faster >>than the RECODE approach I was using. [The speedup was for a RECODE >>with hundreds of clauses.] And I'm pretty sure I tested it myself at that point (using SPSS 9), and had it work for me. I was going to post you a nice demonstration (SPSS 14). Instead, the test run, with problems, is below. You will see, - The auto-generated template file appears, as stated, to be a normal SPSS data file; it can be GET FILEd and LISTed. (By the way, SPSS 14 datasets don't seem to work. Design, or oversight?) And it can be APPLYed, and work properly. - BUT, the user-generated template file fails in a very interesting way: A. There's no error message B. AUTORECODE obviously reads the template file. You'll see that it assigns VALUE LABELS for the specifications in the template file. (AUTORECODE always assigns the character source values as labels for the numerical target values.) C. However, it seems to create and apply a whole new set of RECODE specifications: - The new specifications recode the values in alphabetical order (sigh). - The new target values are numbered sequentially after the user-specified ones. - The correct VALUE LABELS are assigned for the new specifications; the target variable therefore has labels for both the user-specified, desired, target values, and the (apparently) generated target values. SPSS, Inc: Comments? The following run, SPSS draft output using 14.0.2, illustrates all of the above. * ................................................... . * ............ AUTORECODE, create a template ...... . GET FILE=TestData. LIST. List |-----------------------------|---------------------------| |Output Created |25-OCT-2006 14:12:22 | |-----------------------------|---------------------------| C:\Documents and Settings\Richard\My Documents\Temporary\SPSS \2006-10-23 Moser - Is it possible to create custom Template files DATA.SAT CharVar Alpha Beta Gamma Delta Epsilon Eta Theta Number of cases read: 7 Number of cases listed: 7 DATASET DECLARE AutoTmpl. AUTORECODE CharVar /INTO NmbrAuto /SAVE TEMPLATE=AutoTmpl. LIST. List |-----------------------------|---------------------------| |Output Created |25-OCT-2006 14:12:22 | |-----------------------------|---------------------------| C:\Documents and Settings\Richard\My Documents\Temporary\SPSS \2006-10-23 Moser - Is it possible to create custom Template files DATA.SAT CharVar NmbrAuto Alpha 1 Beta 2 Gamma 6 Delta 3 Epsilon 4 Eta 5 Theta 7 Number of cases read: 7 Number of cases listed: 7 * ............ Load and list the template ...... . GET FILE=AutoTmpl. LIST. List |-----------------------------|---------------------------| |Output Created |25-OCT-2006 14:12:23 | |-----------------------------|---------------------------| C:\Documents and Settings\Richard\My Documents\Temporary\SPSS \2006-10-23 Moser - Is it possible to create custom Template files GENERATED TEMPLATE.SAT Source_ Target_ Alpha 1 Beta 2 Delta 3 Epsilon 4 Eta 5 Gamma 6 Theta 7 Number of cases read: 7 Number of cases listed: 7 * ............ Create a user's template ...... . NEW FILE. DATA LIST FREE / Source_ (A8) Target_ (F3). * ... BEGIN DATA * ... Alpha 101 Beta 102 Gamma 103 Delta 104 Epsilon 105 Theta 107. * ... END DATA. BEGIN DATA Alpha 101 Beta 102 Gamma 103 Delta 104 Epsilon 105 Eta 106 Theta 107. END DATA. * ............ List and save template ...... . * - 'Eta' is not included in values to be recoded . * - Variable "Source_" is (A8); variable to be . * recoded is (A12). SORT CASES BY Source_. SAVE OUTFILE=UserTmpl. * ............ Load and list the template ...... . GET FILE=UserTmpl. LIST. List |-----------------------------|---------------------------| |Output Created |25-OCT-2006 14:12:26 | |-----------------------------|---------------------------| C:\Documents and Settings\Richard\My Documents\Temporary\SPSS \2006-10-23 Moser - Is it possible to create custom Template files TEMPLATE CREATED BY USER.SAT Source_ Target_ Alpha 101 Beta 102 Delta 104 Epsilon 105 Eta 106 Gamma 103 Theta 107 Number of cases read: 7 Number of cases listed: 7 * ............ Recode, with both templates ...... . GET FILE=TESTDATA. AUTORECODE CharVar /INTO NmbrAuto /APPLY TEMPLATE=AutoTmpl. AUTORECODE CharVar /INTO NmbrUser /APPLY TEMPLATE=UserTmpl. FORMATS NmbrUser (F4). LIST. List |-----------------------------|---------------------------| |Output Created |25-OCT-2006 14:12:27 | |-----------------------------|---------------------------| C:\Documents and Settings\Richard\My Documents\Temporary\SPSS \2006-10-23 Moser - Is it possible to create custom Template files DATA.SAT CharVar NmbrAuto NmbrUser Alpha 1 108 Beta 2 109 Gamma 6 113 Delta 3 110 Epsilon 4 111 Eta 5 112 Theta 7 114 Number of cases read: 7 Number of cases listed: 7 DISPLAY DICTIONARY. File Information |-----------------------------|---------------------------| |Output Created |25-OCT-2006 14:12:27 | |-----------------------------|---------------------------| C:\Documents and Settings\Richard\My Documents\Temporary\SPSS \2006-10-23 Moser - Is it possible to create custom Template files DATA.SAT Variable Information |--------|--------|------|------------|-------|---------|-------|-------| |Variable|Position|Label |Measurement |Column |Alignment|Print |Write | | | | |Level |Width | |Format |Format | |--------|--------|------|------------|-------|---------|-------|-------| |CharVar |1 |<none>|Nominal |14 |Left |A12 |A12 | |--------|--------|------|------------|-------|---------|-------|-------| |NmbrAuto|2 |<none>|Nominal |10 |Right |F1 |F1 | |--------|--------|------|------------|-------|---------|-------|-------| |NmbrUser|3 |<none>|Nominal |10 |Right |F4 |F4 | |--------|--------|------|------------|-------|---------|-------|-------| Variables in the working file Variable Values |--------|---|-------| |Value | |Label | |--------|---|-------| |NmbrAuto|1 |Alpha | | |2 |Beta | | |3 |Delta | | |4 |Epsilon| | |5 |Eta | | |6 |Gamma | | |7 |Theta | |--------|---|-------| |NmbrUser|101|Alpha | | |102|Beta | | |103|Gamma | | |104|Delta | | |105|Epsilon| | |106|Eta | | |107|Theta | | |---|-------| | |108|Alpha | | |109|Beta | | |110|Delta | | |111|Epsilon| | |112|Eta | | |113|Gamma | | |114|Theta | |--------|---|-------| |
There seem to be two threads here:
1. Can you create/apply templates with non-ordinal arrangements? Yes. A template file is actually just an SPSS data file; so you can create your own following any logic you want -- but you're on your own if it doesn't work. ;-) 2. Applying a template from a string of one defined width to a string of a different defined width doesn't work as one would expect for the same values (e.g. a value of "abc" from an 8-character string variable applied to a value of "abc" from a 12-character string variable). This is an undocumented limitation -- but a cursory test suggests that it's only problematic when the string variable in the template is shorter of the two. So a value of "abc" from a template for a 12-character string variable will treat a value of "abc" in an 8-character string variable as the same value and apply the same autorecode value. *applying template created with longer string to shorter string works for same values. data list free /longstring (a12). begin data abc def ghi jkl end data. autorecode longstring /into numvar /save template='c:\temp\autotemplate.sat' /print. data list free /shorterstring (a10). begin data aaa abc def ghi jkl end data. autorecode shorterstring /into numvar /apply template='c:\temp\autotemplate.sat' /print. ________________________________ From: SPSSX(r) Discussion on behalf of Richard Ristow Sent: Mon 10/30/2006 6:07 PM To: [hidden email] Subject: Re: Is it possible to create custom Template files? At 02:18 PM 10/23/2006, Moser, Gary wrote: >I am very pleased with the subcommands 'apply template' and 'save >template' on the autorecode command. What if I want to create a >template that has numbers assigned to values in non-ordinal >arrangements? After posting a failure on Wed, 25 Oct 2006 14:43:37 -0400, I looked again, and, "By George, I think he's got it!" - Alan Jay Lerner From the SPSS 14 Command Syntax Reference, article on AUTORECODE, p.166: >APPLY TEMPLATE Subcommand >The APPLY TEMPLATE subcommand allows you to apply a previously saved >autorecode template. >.. Value mappings from the template are applied first. All remaining >values are recoded into values higher than the last value in the >template 'Remaining values'; i.e. values the source variable takes on, that are not in variable "Source_" in the template. AND, for this purpose, for string values to be the 'same', they must have the same length. (If this is documented, I haven't seen it.) Below is a revised run; it's SPSS draft output, release 14. It AUTORECODEs an 8-character variable, generating a template; and creates a user template, in which variable "Source_" has length 8. Both those templates work properly when applied to the original variable. Neither of them give the desired results applied to a 12-character copy of the original variable; for both AUTORECODE regards the specifications from the template as not matching, and generates new recode specifications according to the rule quoted above. * ............ AUTORECODE, create a template ...... . GET FILE=TestData. LIST. |-----------------------------|---------------------------| |Output Created |30-OCT-2006 18:10:39 | |-----------------------------|---------------------------| C:\Documents and Settings\Richard\My Documents\Temporary\SPSS \2006-10-23 Moser - Is it possible to create custom Template files DATA.SAV CharVar Alpha Beta Gamma Delta Epsilon Eta Theta Number of cases read: 7 Number of cases listed: 7 AUTORECODE CharVar /INTO NmbrAuto /SAVE TEMPLATE=AutoTmpl. LIST. |-----------------------------|---------------------------| |Output Created |30-OCT-2006 18:10:39 | |-----------------------------|---------------------------| C:\Documents and Settings\Richard\My Documents\Temporary\SPSS \2006-10-23 Moser - Is it possible to create custom Template files DATA.SAV CharVar NmbrAuto Alpha 1 Beta 2 Gamma 6 Delta 3 Epsilon 4 Eta 5 Theta 7 Number of cases read: 7 Number of cases listed: 7 * ............ Load and list the template ...... . GET FILE=AutoTmpl. LIST. |-----------------------------|---------------------------| |Output Created |30-OCT-2006 18:10:39 | |-----------------------------|---------------------------| C:\Documents and Settings\Richard\My Documents\Temporary\SPSS \2006-10-23 Moser - Is it possible to create custom Template files GENERATED TEMPLATE.SAT Source_ Target_ Alpha 1 Beta 2 Delta 3 Epsilon 4 Eta 5 Gamma 6 Theta 7 Number of cases read: 7 Number of cases listed: 7 * ............ Create a user's template ...... . NEW FILE. DATA LIST FREE / Source_ (A08) Target_ (F3). * The data line, below, omits 'Eta', code 106. . BEGIN DATA Alpha 101 Beta 102 Gamma 103 Delta 104 Epsilon 105 Theta 107 END DATA. * ... Alpha 101 Beta 102 Gamma 103 Delta 104 * ... Epsilon 105 Eta 106 Theta 107. * ............ List and save template ...... . * - 'Eta' is not included in values to be recoded . SORT CASES BY Source_. SAVE OUTFILE=UserTmpl. * ............ Load and list the template ...... . GET FILE=UserTmpl. LIST. |-----------------------------|---------------------------| |Output Created |30-OCT-2006 18:10:41 | |-----------------------------|---------------------------| C:\Documents and Settings\Richard\My Documents\Temporary\SPSS \2006-10-23 Moser - Is it possible to create custom Template files TEMPLATE CREATED BY USER.SAT Source_ Target_ Alpha 101 Beta 102 Delta 104 Epsilon 105 Gamma 103 Theta 107 Number of cases read: 6 Number of cases listed: 6 * ............ Recode, with both templates, ...... . * 8-character and 12-character . * source variables. . GET FILE=TESTDATA. STRING Char12 (A12). COMPUTE Char12 = Charvar. AUTORECODE CharVar /INTO TgAuto /APPLY TEMPLATE=AutoTmpl. AUTORECODE CharVar /INTO TgUser /APPLY TEMPLATE=UserTmpl. AUTORECODE Char12 /INTO TgAuto12 /APPLY TEMPLATE=AutoTmpl. AUTORECODE Char12 /INTO TgUser12 /APPLY TEMPLATE=UserTmpl. FORMATS TgAuto TO TgUser12 (F4). LIST. |-----------------------------|---------------------------| |Output Created |30-OCT-2006 18:10:41 | |-----------------------------|---------------------------| C:\Documents and Settings\Richard\My Documents\Temporary\SPSS \2006-10-23 Moser - Is it possible to create custom Template files DATA.SAV CharVar Char12 TgAuto TgUser TgAuto12 TgUser12 Alpha Alpha 1 101 8 108 Beta Beta 2 102 9 109 Gamma Gamma 6 103 13 113 Delta Delta 3 104 10 110 Epsilon Epsilon 4 105 11 111 Eta Eta 5 108 12 112 Theta Theta 7 107 14 114 Number of cases read: 7 Number of cases listed: 7 DISPLAY DICTIONARY. |-----------------------------|---------------------------| |Output Created |30-OCT-2006 18:10:41 | |-----------------------------|---------------------------| C:\Documents and Settings\Richard\My Documents\Temporary\SPSS \2006-10-23 Moser - Is it possible to create custom Template files DATA.SAV Variable Information |--------|--------|------|-----------|------|---------|------|------| |Variable|Position|Label |Measurement|Column|Alignment|Print |Write | | | | |Level |Width | |Format|Format| |--------|--------|------|-----------|------|---------|------|------| |CharVar |1 |<none>|Nominal |10 |Left |A8 |A8 | |--------|--------|------|-----------|------|---------|------|------| |Char12 |2 |<none>|Nominal |14 |Left |A12 |A12 | |--------|--------|------|-----------|------|---------|------|------| |TgAuto |3 |<none>|Nominal |8 |Right |F4 |F4 | |--------|--------|------|-----------|------|---------|------|------| |TgUser |4 |<none>|Nominal |8 |Right |F4 |F4 | |--------|--------|------|-----------|------|---------|------|------| |TgAuto12|5 |<none>|Nominal |10 |Right |F4 |F4 | |--------|--------|------|-----------|------|---------|------|------| |TgUser12|6 |<none>|Nominal |10 |Right |F4 |F4 | |--------|--------|------|-----------|------|---------|------|------| Variables in the working file Variable Values |--------|---|-------| |Value | |Label | |--------|---|-------| |TgAuto |1 |Alpha | | |2 |Beta | | |3 |Delta | | |4 |Epsilon| | |5 |Eta | | |6 |Gamma | | |7 |Theta | |--------|---|-------| |TgUser |101|Alpha | | |102|Beta | | |103|Gamma | | |104|Delta | | |105|Epsilon| | |107|Theta | | |108|Eta | |--------|---|-------| |TgAuto12|1 |Alpha | | |2 |Beta | | |3 |Delta | | |4 |Epsilon| | |5 |Eta | | |6 |Gamma | | |7 |Theta | | |---|-------| | |8 |Alpha | | |9 |Beta | | |10 |Delta | | |11 |Epsilon| | |12 |Eta | | |13 |Gamma | | |14 |Theta | |--------|---|-------| |TgUser12|101|Alpha | | |102|Beta | | |103|Gamma | | |104|Delta | | |105|Epsilon| | |107|Theta | | |---|-------| | |108|Alpha | | |109|Beta | | |110|Delta | | |111|Epsilon| | |112|Eta | | |113|Gamma | | |114|Theta | |--------|---|-------| |
At 01:53 AM 10/31/2006, Oliver, Richard wrote:
>1. Can you create/apply templates with non-ordinal arrangements? Yes. >A template file is actually just an SPSS data file; so you can create >your own following any logic you want -- but you're on your own if it >doesn't work. ;-) > >2. Applying a template from a string of one defined width to a string >of a different defined width doesn't work as one would expect for the >same values (e.g. a value of "abc" from an 8-character string variable >applied to a value of "abc" from a 12-character string variable). This >is an undocumented limitation -- but a cursory test suggests that it's >only problematic when the string variable in the template is shorter >of the two. So a value of "abc" from a template for a 12-character >string variable will treat a value of "abc" in an 8-character string >variable as the same value and apply the same autorecode value. THANK you. That's something I didn't test, and missed. It's a major difference, and a major improvement: you can make a template work for all sorts of strings simply by making variable Source_ very long. |
Free forum by Nabble | Edit this page |