[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Transformations
At 11:43 AM 2/11/2004 +1100, Jason Payne wrote:
Stata does things kind of backwards from SPSS:
I am trying to transform data in variables. What is the equivalent STATA
syntax for this SPSS command
if (var1=2) var2=1.
gen var2 = 1 if var1==2
Note the ==
If var2 already exists, instead say
replace var2 = 1 if var1==2
But, what do you want when var1 does not equal 2? Missing? A 0-1
dichotomy? There may be some other ways to approach this, depending on what
your ultimate goal is.
This syntax only works if you want to create a new variable, however in
some cases I might with to modify an existing variable for one case
only. This is particularly useful in cleaning string variables where
there are spelling mistakes. In SPSS I would just type:
replace stringvar="SPSS" in 1
if (caseid=1) stringvar='SPSS'.
if (caseid=2) stringvar='STATA'.
replace stringvar="STATA" in 2
I'm assuming these are the first and second cases in your data. If not
necessarily so, and caseid is a variable in your data set, then try
replace stringvar="SPSS" if caseid==1
replace stringvar="STATA" if caseid==2
Or, just go in to the data editor and do it! Lot easier sometimes really.
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
WWW (personal): http://www.nd.edu/~rwilliam
WWW (department): http://www.nd.edu/~soc
* For searches and help try: