Statalist


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

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


From   Ekaterina Hertog <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: counting the number of nonmissing values in varlist for each observation
Date   Mon, 28 Dec 2009 19:39:35 +0100

Dear Martin,
Thank you very much for the advice! Your suggestion works!
Dear Maarten and Eric thank you very much for your earlier suggestions! In the end I used the way suggested by Martin as it seemed to work best with my data, but looking into alternative possibilities was very useful!
warm regards,
Ekaterina

Weiss wrote:
<>

Just change the "fammem" vars to missing based on your condition before you use -egen-, then:

***
forv i=1/10{
	replace fammem`i'=. if fammem`i'_liv==30
}
***

HTH
Martin

-------- Original-Nachricht --------
Datum: Mon, 28 Dec 2009 18:31:42 +0100
Von: Ekaterina Hertog <[email protected]>
An: "[email protected]" <[email protected]>
Betreff: Re: st: counting the number of nonmissing values in varlist for each observation

Dear Martin,
Thank you very much for the advice! Sorry I should have looked at -help varlist-, I only thought of -help egen-. I have got an additional question, I just realised that a couple of hundred of individuals in my dataset named family members who have passed away. For these people fammem1_liv etc has a particular value (30). Is it possible to specify the varlist for rownonmiss in a way that it will presume fammem1 to be missing if fammem1_live==30, fammem2 missing if fammem2_live==30 etc.?
sincerely yours,
Ekaterina

<>

See the rules at -help varlist-: "?" stands for one character...


***
clear*
set obs 10
forv i=1/10{
gen fammem`i'=cond(runiform()<.1,.,1)
gen fammem`i'_liv=.
}
egen nmbfammem= rownonmiss(fammem? fammem??)
su nmbfammem
***


HTH
Martin
-------- Original-Nachricht --------
Datum: Mon, 28 Dec 2009 17:13:40 +0100
Von: Ekaterina Hertog <[email protected]>
An: "[email protected]" <[email protected]>
Betreff: st: counting the number of nonmissing values in varlist for
each observation
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/
*
*   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/


*
*   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