Bookmark and Share

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]

Re: st: -tabulate- looped over levels with -foreach-: how to count each subject only once, and display row percentages?


From   Michael Barker <[email protected]>
To   [email protected]
Subject   Re: st: -tabulate- looped over levels with -foreach-: how to count each subject only once, and display row percentages?
Date   Mon, 3 Feb 2014 11:26:33 -0500

You might be able to accomplish this with the bysort prefix:

bysort Group: tabulate Gender Age, row

I'm not sure where Subject fits into this question, since it is not
mentioned above. Is it the same as Group?

For the row option, I don't see any reason why it wouldn't work. What
happens when you run the commands without the row option?

I think it is always useful to use display to make sure your macros
are really what you think they are:

qui levelsof Group, local(levels)
foreach l of local levels {
    display "Current Group is -`I'-"
    tabulate Gender Age if Group == `l', row
}


On Sat, Feb 1, 2014 at 3:12 PM, Michael McCulloch
<[email protected]> wrote:
> 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/
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index