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   Fred Wolfe <[email protected]>
To   [email protected]
Subject   Re: st: creating a numlist from a variable
Date   Fri, 25 Feb 2005 15:42:48 -0600

Here is a quick and dirty way to do it that requires no macro manipulation.

gen var2 = var1 if var1 != 0
levels var2,gen(mymac)
drop var1

Fred Wolfe

At 03:34 PM 2/25/2005, you wrote:
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/

Fred Wolfe
National Data Bank for Rheumatic Diseases
Wichita, Kansas
Tel (316) 263-2125     Fax (316) 263-0761
[email protected]


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