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

RE: st: forvalues and _N


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: forvalues and _N
Date   Fri, 3 Sep 2004 18:29:02 +0100

Contrariwise, it is good that you have 
worked out the logic for yourself. If 
your labels are all unique, then there 
is no obvious gain in using -sencode- or my -seqencode-
(not -oencode-, which does something else again). 

Nick 
n.j.cox@durham.ac.uk 

Wallace, John
 
> 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.

Nick Cox 
 
> 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:
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index