Bookmark and Share

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]

Re: st: recoding a long-level categorical variable


From   Richard Goldstein <[email protected]>
To   [email protected]
Subject   Re: st: recoding a long-level categorical variable
Date   Fri, 13 Sep 2013 13:29:50 -0400

If you have made a typo or 2, then there is; note that
(7230-5760)/15=98; so, do you want 1-98?

note also, however, that in your code below, you are repeating some
numbers (e.g., 7215 appears on both the first (=96) and second (=95)
lines; this appears to be an error

if you want each new value of a new variable to increase by 1 for each
set of 15 consecutive numbers in the old variable, then, yes, you could
put this is a forval loop; however, this may not be your situation so
please clarify

Rich

On 9/13/13 1:19 PM, Jonathan Furszyfer wrote:
> 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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index