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

From |
"Martin Weiss" <Martin.Weiss1@gmx.de> |

To |
statalist@hsphsun2.harvard.edu |

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

Date |
Mon, 28 Dec 2009 18:18:18 +0100 |

<> But your solution builds critically on the presence of -var label-s corresponding to the -varname-s that Ekaterina initially posted. This may or may not be true for her data, but replicating the names one for one in a -var label- seems like a strange redundancy to me. Anyway, you can use -ds- (http://www.stata-journal.com/article.html?article=dm0040) with the variable names as well. Just say -ds *_liv, not- Another assumption in this solution is that there are no other variables apart from the two groups described by Ekaterina. Any other variable whose name happens not to end in "_liv" would be picked up by -ds- as well... HTH Martin -------- Original-Nachricht -------- > Datum: Mon, 28 Dec 2009 10:50:35 -0600 > Von: "Eric Booth" <ebooth@ppri.tamu.edu> > An: statalist@hsphsun2.harvard.edu > Betreff: st: RE: counting the number of nonmissing values in varlist for each observation > <> > > (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/ > > -- GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01 * * 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: 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>

**st: RE: counting the number of nonmissing values in varlist for each observation***From:*"Eric Booth" <ebooth@ppri.tamu.edu>

- Prev by Date:
**st: stata mp 10.1 issue** - Next by Date:
**Re: st: counting the number of nonmissing values in varlist for each observation** - Previous by thread:
**st: RE: counting the number of nonmissing values in varlist for each observation** - Next by thread:
**st: r(603) error when using mi impute command with network version of Stata 11** - Index(es):

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