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

RE: st: forvalues and _N


From   "Wallace, John" <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: forvalues and _N
Date   Fri, 3 Sep 2004 10:23:06 -0700

Thanks for the reference Nick.  It does look like the same problem.  I was
surprised to think that I was the first one to come across this and was
thinking I might have a candidate for my first public .ado contribution
(after considerable revision to make it more general). Pity.

-JW

-----Original Message-----
From: Nick Cox [mailto:[email protected]] 
Sent: Friday, September 03, 2004 9:39 AM
To: [email protected]
Subject: RE: st: forvalues and _N

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. 

Nick 
[email protected] 

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