Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Re: st: Calculate response rate (proportion of non-missing value)
From
Maarten buis <[email protected]>
To
[email protected]
Subject
st: Re: st: Calculate response rate (proportion of non-missing value)
Date
Mon, 14 Feb 2011 08:40:40 +0000 (GMT)
--- On Mon, 14/2/11, Guo Chen wrote:
> I have a survey data right now and need to calculate the
> response rate to each question by whether the interviewee
> is in a group, and then do a ttest of the response rates
> between the two groups of people.
To get the response rate you need a dumy variable that is 1
when the respondent answered to that question and 0 otherwise.
The -missing()- function gives you exactly the opposite. If
you precede that with a -!- you reverse the logical statement.
Without thinking about it I literally read -!missing()- as
"not missing". For more on this see: <http://www.stata.com/support/faqs/data/trueorfalse.html> and
an application of this logic on this text on one of my T-shirts:
<http://www.stata.com/meeting/13uk/i/mbuis_talk_big.jpg>)
Once you have that dummy, then the rate is just the mean of
that dummy. For convenience you can us -ds- to get a list of
variables you want to test, and use a -foreach- loop to loop
over that list, but that is just icing on the cake; it saves
you typing (and thus diminishes the chance of a typo...).
*-------------------------- begin example -------------------
sysuse nlsw88, clear
ds race, not
local varl "`r(varlist)'"
// other (3) and missing values will be turned into missing
// so 1 is black, 0 is white
gen black = race == 2 if race <=2
gen byte miss = .
foreach var of local varl {
qui replace miss = !missing(`var')
di "================= testing response rate for `var'"
ttest miss, by(black)
}
*-------------------------- end example -----------------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )
Hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* 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/