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 16:51:03 -0600

At 04:30 PM 2/25/2005, you wrote:
That provides a listing (with the change of "gen(mymac) to "local(mymac)" in
line 2). But it still does not seem to be a numlist that one can work with,
for example in graphing, e.g.,

line y1 y2 y3 x1, xline($mymac)

Try these:

sysuse auto
levels foreign, local(mymac)
scatter rep78 headroom,ylab(0[1]5) yline(`mymac')

global gmac "1 2 3"
scatter rep78 headroom,ylab(0[1]5) yline($gmac)

Fred





Peter


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] <mailto:[email protected]>
http://wat1203.ucr.edu <http://wat1203.ucr.edu>


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Fred Wolfe
Sent: Friday, February 25, 2005 1:43 PM
To: [email protected]
Subject: Re: st: creating a numlist from a variable

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/

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