Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: recoding variables


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   Re: st: recoding variables
Date   Wed, 8 Oct 2003 18:14:16 +0100

Jim Seward 

> I have a database of scores of subjects who were given the same
> memory test on an annual basis.  The data look  something like:
> 
> SUBJECT   YEAR 1 SCORE   YEAR 2 SCORE    YEAR 3 SCORE.....
> 
> Tom            15             16              14
> Dick           12             13              10
> Harry               15             14              15
> .
> .
> .
> 
> 
> I would like to determine if the subjects scores tend to increase
> or decrease with time.  I was thinking of using linear regression,
> with YEAR as the x variable and SCORE as the y variable.
> 
> In order to do that, I think that I have to recode the data
> thusly:
> 
> SUBJECT   YEAR      SCORE
> Tom       1         15
> Tom       2         16
> Tom       3         14
> Dick      1         12
> Dick      2         13
> Dick      3         10
> Harry          1         15
> Harry          2         14
> Harry          3         15
> 
> Does anyone know of a way to do this in Stata?

Yes. This is a -reshape-. 

First off, your variable names possibly are 

subject year1score year2score year3score 

you might want to -rename- them to a standard 
stub + suffix form: 

forval i = 1/3 { 
	rename year`i'score score`i' 
} 

then you want 

reshape long score, i(subject) j(year) 

See [R] reshape and for further tricks 
and examples
http://www.stata.com/support/faqs/data/reshape3.html

Nick 
[email protected] 
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index