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

RE: st: forvalues and _N

From   "Nick Cox" <>
To   <>
Subject   RE: st: forvalues and _N
Date   Fri, 3 Sep 2004 17:38:37 +0100

This looks like the problem tackled already by 
Roger Newson's -sencode- (SSC) and my -oencode- 
(private domain). Last time I looked, Roger's 
could do things mine couldn't do, and versa vice, 
so I guess I should make mine public too. 


Wallace, John
> Thanks for the explanation, Nick. What I was seeking to do 
> isn't all that
> different from how -encode- works, but I wanted to be in 
> specific control of
> the association between the numeric variable and the 
> alphanumeric label.  I
> believe -encode- generates its new numeric variable in 
> ascending alphabetic
> order of the encoded string values.  The order the string 
> values had in my
> original data set was structure I needed to retain, which I 
> did using the
> following:
> . insheet using [tab-delimited text file]
> . keep v1 descriptions
> . gen pset = _n /*to record the initial order of observations*/
> . move pset  v1
> . rename v1 probesetname /*the string data comes in with the 
> v1 generic
> variable name*/
> . forval e = 1 /`=_N'{ /*thanks to Fred Wolfe*/
> 	.local pval = probesetname[`e']
> 	.label define psetlab `e' "`pval'", add
> .}
> .label values pset psetlab /*the desired association*/

*   For searches and help try:

© Copyright 1996–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index