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

st: creating a numlist from a variable


From   "Peter J. Burke" <[email protected]>
To   "statalist" <[email protected]>
Subject   st: creating a numlist from a variable
Date   Fri, 25 Feb 2005 13:34:19 -0800

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? 
 

Peter J. Burke
Professor and Chair
Department of Sociology
University of California
Riverside, CA 92521-0419
Phone: 951/827-7198
Fax: 951/827-3330
[email protected] 
http://wat1203.ucr.edu <http://wat1203.ucr.edu/> 


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