<>
(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/
<<winmail.dat>>