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

From |
"Eric Booth" <ebooth@ppri.tamu.edu> |

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

Subject |
st: RE: counting the number of nonmissing values in varlist for each observation |

Date |
Mon, 28 Dec 2009 10:50:35 -0600 |

<> (apologies if this sends twice) .... There are a couple of options here: ****** clear set obs 10 forv n = 1/10 { g fammem`n' = abs(round(rnormal()*10)) label var fammem`n' "fammem`n'" g fammem`n'_liv = abs(round(rnormal()*10)) label var fammem`n'_liv "fammem`n'_liv" } ds, not(varlabel "*_liv") local one `r(varlist)' di "`r(varlist)'" //1. using ds list egen nmbfammem4 = rownonmiss(`one') //2. using varlabel wildcards egen nmbfammem = rownonmiss(fammem? fammem??) //3. just list all the vars (decreasingly useful as the # of vars increases) egen nmbfammem2 = rownonmiss(fammem1 fammem2 fammem3 fammem4 fammem5 fammem6 fammem7 fammem8 fammem9 fammem10) //4. rename vars temporarily foreach v of local one { rename `v' aa`v' } egen nbfamem3 = rownonmiss(aafammem*) foreach v of local one { rename aa`v' `v' } li nbfamem* ******* ~ Eric __ Eric A. Booth Public Policy Research Institute Texas A&M University ebooth@ppri.tamu.edu Office: +979.845.6754 On Dec 28, 2009, at 10:13 AM, Ekaterina Hertog wrote: Dear all, I need to create a variable which will contain the count the number of nonmissing values in varlist for each observation for the variables called fammem1, fammem2 etc. I came up with the following command: egen nmbfammem= rownonmiss (fammem*) The problem is I have two types of variables starting with fammem: fammem1, fammem2 etc. until fammem10 (which note one's family members) and fammem1_liv, fammem2_liv etc. (which notes whether one lives with the given family member in the same household or not) and I only want to create the count of one's family members. Is it possible in Stata 11 to specify varlist as all variables the name of which start with fammem followed by a number between 1 and 10? I will be very grateful for advice, Sincerely yours, Ekaterina * * 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/

`<<winmail.dat>>`

**Follow-Ups**:**Re: st: RE: counting the number of nonmissing values in varlist for each observation***From:*"Martin Weiss" <Martin.Weiss1@gmx.de>

**References**:**st: Cannot allocate more than 779 MB to STATA11***From:*roland andersson <rolandersson@gmail.com>

**Re: st: Cannot allocate more than 779 MB to STATA11***From:*Neil Shephard <nshephard@gmail.com>

**Re: st: Cannot allocate more than 779 MB to STATA11***From:*roland andersson <rolandersson@gmail.com>

**Re: st: Cannot allocate more than 779 MB to STATA11***From:*Neil Shephard <nshephard@gmail.com>

**Re: st: Cannot allocate more than 779 MB to STATA11***From:*Robert A Yaffee <bob.yaffee@nyu.edu>

**Re: st: Cannot allocate more than 779 MB to STATA11***From:*roland andersson <rolandersson@gmail.com>

**Re: st: Cannot allocate more than 779 MB to STATA11***From:*roland andersson <rolandersson@gmail.com>

**Re: st: Cannot allocate more than 779 MB to STATA11***From:*David Kantor <kantor.d@att.net>

**st: counting the number of nonmissing values in varlist for each observation***From:*Ekaterina Hertog <ekaterina.hertog@sociology.ox.ac.uk>

- Prev by Date:
**RE: st: increasing time burden during resampling** - Next by Date:
**Re: RE: st: increasing time burden during resampling** - Previous by thread:
**Re: st: counting the number of nonmissing values in varlist for each observation** - Next by thread:
**Re: st: RE: counting the number of nonmissing values in varlist for each observation** - Index(es):

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