Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: recoding a long-level categorical variable
From
Jonathan Furszyfer <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: recoding a long-level categorical variable
Date
Fri, 13 Sep 2013 17:19:25 +0000
Dear All,
For methodological reasons, I have to create a 96-level categorical variable, say x, where x={1,2,3,...,96}. The categories of x, however, are conditioned on other variable, y.
y is a continuous variable. More specifically, y=[5760,7230]. N=1,450,708.
In order to generate x, then, I used recode:
recode y (7215 / 7230 = 96 ) ///
(7200/ 7215 = 95 ) ///
(7185/ 7200 = 94 ) ///
.
(5760/5775 = 1), generate (x)
In other words, using recode takes 96 lines of coding (or less if you add several "(#/#)" in a single line).
I was wondering if there is an easier method to simplify 96 lines of coding, probably using loops, foreach and/or forvalues.
Thank you very much!
Best,
Jon-
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/