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: -tabulate- looped over levels with -foreach-: how to count each subject only once, and display row percentages?
From 
 
Michael McCulloch <[email protected]> 
To 
 
[email protected] 
Subject 
 
st: -tabulate- looped over levels with -foreach-: how to count each subject only once, and display row percentages? 
Date 
 
Sat, 1 Feb 2014 12:12:52 -0800 
I've written this command to produce a table, in which I seek to display variables <Age> and <Gender> in columns, over levels <Group> in rows:
qui levelsof Group, local(levels)
foreach l of local levels {
    tabulate Gender Age if Group == `l', row
}
Two questions about which I'd like to ask advice:
1. In my dataset there are multiple observations per Subject. How can I count each Subject only once?
2. Although one can use the -row- option with -tabulate-, in this case within -foreach- looping, the program returns "option row not allowed."
Any advice would be appreciated.
Best wishes,
Michael McCulloch
--
Pine Street Foundation, since 1989
124 Pine Street | San Anselmo | California | 94960-2674  
P: (415) 407-1357 | F: (206) 338-2391 | http://www.PineStreetFoundation.org
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/