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

RE: st: creating a numlist from a variable


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: creating a numlist from a variable
Date   Sun, 27 Feb 2005 18:04:48 -0000

My solution resembles Fred Wolfe's. -levels- 
lets up you put the numlist in a local 
macro or you can pick up r(levels). Both 
are explained in the on-line help. One key 
detail is that -levels- was added to 
official Stata after the release of Stata 8, 
so the manuals do not help here and you 
must -update- to get access to -levels-. 

That said, I can't reproduce anything like 

. global place var1[1]
. forvalues n = 2/38 {
	global place $place " " var1[`n']
. }

. di $place
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
36 0 0

Without an evaluation, literal text such as "var1[1]" 
will get added to the macro. 

Nor can I see that 

line y1 y2 y3 x1, xline(`$mymac') 

could ever work!

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

Peter J. Burke
 
> I think I now have it with the code that Fred Wolfe suggested 
> and then using
> 
> Line y1 y2 y3 x1, xline(`$mymac') 
> 
> I can't say I always understand the use of the quotes, but 
> this time it
> seems to work.
 
> >I am trying to create a numlist, perhaps using a macro, that 
> contains 
> >the non-zero entries from a particular variable. for example 
> with data 
> >like the following excerpt
> >
> >case    id    var1
> >...
> >  34. |   34     0 |
> >  35. |   35     0 |
> >  36. |   36    36 |
> >  37. |   37     0 |
> >  38. |   38     0 |
> >  39. |   39     0 |
> >  40. |   40     0 |
> >  41. |   41     0 |
> >  42. |   42    42 |
> >  43. |   43     0 |
> >  44. |   44     0 |
> >...
> >
> >I would like to create a numlist that contains "36 42" and omits the 
> >0's. I have tried
> >
> >. global place var1[1]
> >. forvalues n = 2/38 {
> >   2. global place $place " " var1[`n']
> >   3. }
> >
> >. di $place
> >1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> >36 0 0
> >
> >but the global "place" does not actually contain the numbers, and I 
> >cannot figure out how to omit the zeros with an ifcmd, which 
> does not 
> >seem to be allowed with global statements.
> >Does anyone have any suggestions?

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