Expanding a data set and counting iterations

Expanding a data set and counting iterations

Post by Racha » Sun, 22 Jun 2003 06:03:19



Hello,

I have a data file that I would like to expand and add new variables.
The file currently looks like this :

beerN   RbeerN    age   gender   married   educ
   3       2       1      1        1         1
   1       2       1      1        1         2
   2       1       1      1        2         2

etc, etc.

The cases in the variables 'beerN' and 'RbeerN' need to be repeated
with the corresponding demographic variables and two new variables,
'NewVar1' and 'Counter', need to be added.  The result should look
like this :

beerN   RbeerN   age  gender   married   educ  NewVar1  Counter
  3        2      1      1       1        1       0        1
  3        2      1      1       1        1       0        1
  3        2      1      1       1        1       0        1
  3        2      1      1       1        1       1        1
  3        2      1      1       1        1       1        1
  1        2      1      1       1        2       0        2
  1        2      1      1       1        2       1        2
  1        2      1      1       1        2       1        2
  2        1      1      1       2        2       0        3
  2        1      1      1       2        2       0        3
  1        1      1      1       2        2       1        3

I have used the following code to expand the dataset and create the
'NewVar1' variable :

get file 'd:\temp\simcnttry_2.sav'.

LOOP #i= 1 to sum(beerN,RbeerN).
.        compute NewVar1= (#i > beerN).
.        xsave outfile = 'd:\temp\rmlbNtry_2.sav'
            /keep beerN RbeerN age gender married educ educ NewVar1.
end loop.
execute.

How can the 'counter' variable be created ?  Thanks for any advice.
Rachael

 
 
 

Expanding a data set and counting iterations

Post by Raynald Levesqu » Sun, 22 Jun 2003 08:34:56



Quote:>Hello,

>I have a data file that I would like to expand and add new variables.
>The file currently looks like this :

>beerN   RbeerN    age   gender   married   educ
>   3       2       1      1        1         1
>   1       2       1      1        1         2
>   2       1       1      1        2         2

>etc, etc.

>The cases in the variables 'beerN' and 'RbeerN' need to be repeated
>with the corresponding demographic variables and two new variables,
>'NewVar1' and 'Counter', need to be added.  The result should look
>like this :

>beerN   RbeerN   age  gender   married   educ  NewVar1  Counter
>  3        2      1      1       1        1       0        1
>  3        2      1      1       1        1       0        1
>  3        2      1      1       1        1       0        1
>  3        2      1      1       1        1       1        1
>  3        2      1      1       1        1       1        1
>  1        2      1      1       1        2       0        2
>  1        2      1      1       1        2       1        2
>  1        2      1      1       1        2       1        2
>  2        1      1      1       2        2       0        3
>  2        1      1      1       2        2       0        3
>  1        1      1      1       2        2       1        3

>I have used the following code to expand the dataset and create the
>'NewVar1' variable :

>get file 'd:\temp\simcnttry_2.sav'.

>LOOP #i= 1 to sum(beerN,RbeerN).
>.        compute NewVar1= (#i > beerN).
>.        xsave outfile = 'd:\temp\rmlbNtry_2.sav'
>            /keep beerN RbeerN age gender married educ educ NewVar1.
>end loop.
>execute.

>How can the 'counter' variable be created ?  Thanks for any advice.
>Rachael

Try this:

get file 'd:\temp\simcnttry_2.sav'.
compute counter=$casenum.

LOOP #i= 1 to sum(beerN,RbeerN).
.        compute NewVar1= (#i > beerN).
.        xsave outfile = 'd:\temp\rmlbNtry_2.sav'
            /keep beerN RbeerN age gender married educ educ NewVar1
counter.
end loop.
execute.

HTH


Visit My SPSS Pages: http://pages.infinit.net/rlevesqu/index.htm

 
 
 

1. (DBRJ) scripting an iteration of an iteration in 123

Note: Apparently this question has some sort of taboo on it, because
I've posted it in various forms in several groups and gotten absolutely
no response!
I have written a Lotus 123 script program that iterates along a row and
colors certain cells depending on the values displayed relative to
earlier (ie, to the left) cells. If I have several rows, I currently
must write separate scripts, defining a new range for each. I cannot
simply define the range as the upper left- lower right cells with this
program because script iterates by columns, thus losing the
simple "earlier in the same row" feature iterating a row allows.
Can anyone help?
If this is a "dumb", "trivial and obvious", "impossible",
or "inappropriate" question - which might account for the lack of
previous responses - I'd appreciate someone at least telling me.
Thanks.
                                   DBRJ

Sent via Deja.com http://www.deja.com/
Before you buy.

2. PAT pix 501

3. how to change an existing data set's variables order by using data set statement?

4. FA: Nice Quadra 700 on Yahoo...Only $30

5. Parallel dynamic programing, policy iteration, linear prog, value iteration, infinite horizon problems

6. How to turn off the bell in Demacs

7. Changing Default Iteration Setting in Excel 4

8. changing the assemblykeyfile attribute from the command line

9. Iteration loops with sets and lists

10. Please Help - HP Scanjet 4c ands NT

11. Compare two data sets and find any row has new data points

12. create data entry from existing SAS data set ???

13. How to SET two data sets in SQL?