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

st: Re: Categorical variable


From   austin nichols <[email protected]>
To   [email protected]
Subject   st: Re: Categorical variable
Date   Fri, 22 Jul 2005 10:13:55 -0400

I sincerely doubt your variable names have spaces in them, so I will
assume they are named v1, v2, etc. up to v99 and have labels "poor
performance", "retirement", etc. assigned via the -label var v1 "poor
performance" command.

Then you can

gen byte onevar=.
forval i=1/99 {
 local l: var la v`i'
 la def onevar `i' "`l'", modify
 replace onevar=`i' if v`i'==1
}
la val onevar onevar
tab onevar

and if you really need a string variable, you can

decode onevar, gen(onestrvar) 

-----Original Message-----
From: Katarina Sikavica [mailto:[email protected]]
Sent: Friday, July 22, 2005 9:19 AM
Subject: Re: st: Categorical variable

actually: I've collected data on reported reasons for CEO turnover (as
stated in newspaper articles); my dummy variables look like this:

- poor performance (1/0)
- retirement (1/0)
- policy differences (1/0)
- ....

Now I would like to create a single new variable called "reason" that
looks like this:
one and only variable "reason" coded as follows:

1 poor performance
2 retirement
3 policy differences
4 ....

best,
Katy

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