Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: assigning codes to variables in bulk


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: assigning codes to variables in bulk
Date   Thu, 23 Feb 2006 18:26:18 -0000

The code is short, but if time is too this looks like 
the wrong way to go. The issue is that -recode- is 
a few hundred lines of Stata to interpret, and so, 
ceteris paribus, not the sort of thing you want to 
loop over. 

I am not a betting person, but I'd guess wildly that Austin's 
approach is faster. 

Nick 
[email protected] 

Richard Williams
 
> At 12:14 PM 2/23/2006, you wrote:
> >I am doing the following and fervently believe that there are more
> >elegant, faster ways to do this. (I am working in Stata 8.2 
> but will be
> >updating to 9 any day now.) Occupational history codes 
> jobnum1-jobnum16
> >each take one of 500 values from 003 to 909, and I am assigning a
> >Nam-Powers status value (1 to 100) to each occupation held.
> >
> >forvalues i=1 to 16{
> >gen jobstatus`i'=.
> >}
> 
> how about (not tested)
> 
> forvalues i = 1 to 16 {
>          recode jobnum`i' (003=86)(004=77)..., gen(jobstatus`'i')
> }
> 
> or else something like
> 
> recode jobnum1 jobnum2...jobnum16 (003=86)..., gen(jobstatus1 
> jobstatus2...)

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