The mean of an indicator variable, AKA dummy (with outcomes 1 for true
and 0 for false), is equal to the proportion of positive responses.
So -sum A1_*- gives you a list of proportions, easily turned into
percentages. Each proportion times N gives you the frequency. Did
you need something more complicated? The format you wanted is
available via the code:
foreach v of varlist A1_* {
su `v', meanonly
di as res "`v'" _col(12) %3.0f r(mean)*r(N) _col(20) %5.2f 100*r(mean)
}
or you could put it in a program:
cap prog drop mysum
prog def mysum
syntax varlist [if] [in]
di as res "Varname" _col(12) "Freq" _col(20) "Percent"
foreach v of varlist `varlist' {
su `v' `if' `in', meanonly
di as res "`v'" _col(12) %3.0f r(mean)*r(N) _col(20) %5.2f 100*r(mean)
}
end
and run, e.g.
. sysuse auto, clear
. qui tab rep78, g(A1_)
. mysum A1_*
Varname Freq Percent
A1_1 2 2.90
A1_2 8 11.59
A1_3 30 43.48
A1_4 18 26.09
A1_5 11 15.94
and you can add other columns in a similar fashion, e.g. number
missing, etc. If you want to copy into another program on the Windows
OS, simply select, right click and choose Copy Table, and paste the
table into your word processor, spreadsheet, etc.
On 3/16/06, Munro, Cameron <munro@rand.org> wrote:
> I'm trying to tabulate the % of respondents to a multipunch survey question who answer affirmative to each alternative. In other words:
>
> indiv A1_1 A1_2 A1_3
> 1 0 1 0
> 2 1 0 1
> 3 1 1 0
>
> I can -tabulate- each variable on their own, but I'm looking to have a table across all A1* variables, i.e.
> Freq. Percent
> A1_1 2 66.67
> A1_2 2 66.67
> A1_3 1 33.33
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/