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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: RE: replace loop over var w/ if |

Date |
Sun, 22 Feb 2009 17:59:45 -0000 |

<> Note also that for numeric variables a < . and !missing(a) are equivalent. != . catches .a to .z too. Nick n.j.cox@durham.ac.uk Joseph Coveney 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. * * 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/

**References**:**st: replace loop over var w/ if***From:*John Bunge <jota.be@web.de>

**st: RE: replace loop over var w/ if***From:*"Joseph Coveney" <jcoveney@bigplanet.com>

- Prev by Date:
**Re: st: defining current working directory permanently** - Next by Date:
**st: RE: dummy table** - Previous by thread:
**st: RE: replace loop over var w/ if** - Next by thread:
**st: Reading and Merging Multiple DBF files** - Index(es):

© Copyright 1996–2014 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |