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

From |
"Joseph Coveney" <jcoveney@bigplanet.com> |

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

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

Date |
Sun, 22 Feb 2009 13:06:50 +0900 |

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/

**Follow-Ups**:**st: RE: RE: replace loop over var w/ if***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

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

- Prev by Date:
**st: replace loop over var w/ if** - Next by Date:
**Re: st: chi-square test against a know distribution** - Previous by thread:
**st: replace loop over var w/ if** - Next by thread:
**st: RE: RE: replace loop over var w/ if** - Index(es):

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