|
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 |
|--------|---|-------|
|