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   Joerg Luedicke <[email protected]>
To   [email protected]
Subject   Re: st: Combining 7 variables with the same output into a single frequency table
Date   Wed, 13 Feb 2013 18:00:46 -0500

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

Joerg

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"?
>
> Thank you.
>
> Astha.
> 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
>>
>> Rich
>>
>> On 2/13/13 4:39 PM, Astha Ramaiya wrote:
>>> Dear Nicholas,
>>>
>>> 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
>>>
>>> I have been trying to find something the entire day but haven't been successful. Any help would be very much appreciated.
>>>
>>> Regards,
>>>
>>> Astha.
>> *
>> *   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/

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