Statalist


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

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


From   "Martin Weiss" <[email protected]>
To   [email protected]
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" <[email protected]>
> An: [email protected]
> 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
> [email protected]
> 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/



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