Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: replace loop over var w/ if


From   John Bunge <jota.be@web.de>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: replace loop over var w/ if
Date   Sun, 22 Feb 2009 13:19:02 +0100

thanks joseph

thats exactly what i need!


> -----Ursprüngliche Nachricht-----
> Von: "Joseph Coveney" <jcoveney@bigplanet.com>
> Gesendet: 22.02.09 05:07:35
> An: <statalist@hsphsun2.harvard.edu>
> Betreff: st: RE: replace loop over var w/ if


> John Bunge wrote:
> 
> i have 3 variables called v1d, v2d, v3d which all equal to .
> 
> moreover i have 3 variables a1, a2, a3 which equal to . or some numerical
> value
> 
> i want
> replace v1d = 1 if a1 ~=.
> replace v2d = 1 if a2 ~=.
> replace v3d = 1 if a3 ~=.
> 
> how can i do this in 1 command? with forvalue?
> 
> ------------------------------------------------------------------------------
> --
> 
> Not sure about a single line of code, but the following should work.
> 
> forvalues i = 1/3 {
>     replace v`i'd = 1 if !missing(a`i')
> }
> 
> If you're using v?d variables as flags for nonmissing values in the
> corresponding a? variables, then be aware that v?d will always test True,
> because they'll be either . or 1, both of which are nonzero.  If you're using
> v?d variables as nonmissing-value indicator variable for a?, then the
> following would be better.
> 
> forvalues i = 1/3 {
>     replace v`i'd = !missing(a`i')
> }
> 
> In this case, v?d will be 1 (True) if a? is not missing, and 0 (False)
> otherwise.
> 
> Joseph Coveney
> 
> 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
> 


_______________________________________________________________________
Jetzt 1 Monat kostenlos! WEB.DE FreeDSL - Telefonanschluss + DSL
für nur 17,95 EURO/mtl.!* http://dsl.web.de/?ac=OM.AD.AD008K15039B7069a


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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