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: Combining 7 variables with the same output into a single frequency table


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Combining 7 variables with the same output into a single frequency table
Date   Thu, 14 Feb 2013 01:39:32 +0000

See also -tabm- from SSC (within the -tab_chi- package) or Ben Jann's
-mrtab- (SJ/SSC).

Nick

On Wed, Feb 13, 2013 at 11:00 PM, Joerg Luedicke
<[email protected]> wrote:

> With -egen, rowtotal()- you would add the values of your variables,
> which I believe is not what you want. Going from the example tables
> posted in the OP, then this might be what you want:
>
> *---------------------------
> clear
> set obs 10
> forval i = 1/3 {
>         gen x`i' = runiform() > .7
> }
> gen id = _n
>
> tab1 x*
>
> reshape long x, i(id) j(item)
>
> tab x
> *---------------------------

On Wed, Feb 13, 2013 at 5:00 PM, Astha Ramaiya <[email protected]> wrote:

>> I want the sum of all variables (fever1 - fever7) categorized by 1 and 2.
>>
>> Would the code be the following:
>>
>> egen m_fever = rowtotal(m_fever1, m_fever2, m_fever3, m_fever5, m_fever6, m_fever7) to get the combined freq totals for  "1" and combined freq totals for "2"?

On Feb 13, 2013, at 4:47 PM, Richard Goldstein <[email protected]> wrote:

>>> it is not clear what you are looking for
>>>
>>> if you want the sum of the variables use -egen- with the rowtotal option
>>>
>>> if you want to know whether any of the variables have a "1", use -egen-
>>> with the rowmax option
>>>
>>> if you want something else, please clarify

On 2/13/13 4:39 PM, Astha Ramaiya wrote:

>>>> I have 7 different variables (fever 1, fever 2, fever 3….fever7) with the same output (0=No, 1 = Yes). I want to combine all these variables so that i can calculate prevalence of the morbidity. For example:
>>>>
>>>> Fever 1-7 give the output:
>>>>
>>>> m_fever1 |      Freq.     Percent        Cum.
>>>> ------------+-----------------------------------
>>>>          1 |         50       14.3       14.7
>>>>          2 |        300       85.7      100.00
>>>> ------------+-----------------------------------
>>>>      Total |        350      100.00
>>>>
>>>>
>>>> m_fever2 |      Freq.     Percent   Cum.
>>>> ------------+-----------------------------------
>>>>          1 |         0               0        0
>>>>          2 |        350      100.00      100.00
>>>> ------------+-----------------------------------
>>>>      Total |        350      100.00
>>>>
>>>> m_fever3 |      Freq.     Percent        Cum.
>>>> ------------+-----------------------------------
>>>>          1 |         100       28.6       28.6
>>>>          2 |        250       71.4      100.00
>>>> ------------+-----------------------------------
>>>>      Total |        350      100.00
>>>>
>>>> How can i combine the 3 tables above to give me the following table?
>>>>
>>>> m_fever |      Freq.     Percent        Cum.
>>>> ------------+-----------------------------------
>>>>          1 |         150       14.3       14.7
>>>>          2 |        900       85.7      100.00
>>>> ------------+-----------------------------------
>>>>      Total |        1050      100.00
>>>>

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