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   "Peter J. Burke" <peter.burke@ucr.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: creating a numlist from a variable
Date   Fri, 25 Feb 2005 14:46:07 -0800

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.
Thanks 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
peter.burke@ucr.edu <mailto:peter.burke@ucr.edu>  
http://wat1203.ucr.edu <http://wat1203.ucr.edu> 


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Peter J. Burke
Sent: Friday, February 25, 2005 2:31 PM
To: statalist@hsphsun2.harvard.edu
Subject: RE: st: creating a numlist from a variable

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) 

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
peter.burke@ucr.edu <mailto:peter.burke@ucr.edu> http://wat1203.ucr.edu
<http://wat1203.ucr.edu> 


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Fred Wolfe
Sent: Friday, February 25, 2005 1:43 PM
To: statalist@hsphsun2.harvard.edu
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
>peter.burke@ucr.edu
>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
fwolfe@arthritis-research.org


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

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