Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: How to Tabulate Responses Across 41+ Variables in a Single Household and Store this Information in a New Variable?


From   "Austin Nichols" <[email protected]>
To   [email protected]
Subject   Re: st: RE: How to Tabulate Responses Across 41+ Variables in a Single Household and Store this Information in a New Variable?
Date   Mon, 18 Dec 2006 18:09:26 -0500

Kyra--
Just to elaborate on Nick's response--I agree you should reshape your
data to "long" format (see -help reshape-), but I will add that you
should rethink what you want to do with your data--what exactly would
be the point of summing a variable coded 0, 1, or 2?  A fire unlit for
two cases and then lit "in kitchen" for one would look identical to a
fire unlit for one case and then lit "outside" for two.

I would think you would want to generate two indicators after
reshaping along the lines that Nick indicates, one for "fire in
kitchen" and one for "outside" and then perhaps graph the proportion
of households reporting those conditions to be true by time period:

reshape long d1_ d2_ , i(household) j(time) string
rename d1_  d1
rename d2_  d2
reshape long d, i(household time) j(day)
gen hour=real(substr(time,1,2))
gen minutes=real(substr(time,4,2))
gen imagt=day*24*2+hour*2+(minutes==30)
gen fire_in_kitchen=d==1 if !mi(d)
gen fire_outside=d==2 if !mi(d)
egen m_kitchen=mean(fire_in_k), by(imagt)
egen m_outside=mean(fire_out), by(imagt)
line m_* imagt

though I'm sure you can get a useful table that corresponds to such a
graph as well (it's just harder to read).

On 12/18/06, Nick Cox <[email protected]> wrote:
First, a general comment very often made on this list. You
have panel data but in a wide data structure. Many, indeed
most, of the manipulations you will want to do would be much easier
if you -reshape-d your data to long.

The -reshape- sounds like a double -reshape-

reshape long d1_ d2_ ... , i(household) j(time) string
rename d1_  d1
rename d2_  d2
...
reshape long d, i(household time) j(day)

Second, "didn't work" is meaningless even to Stata experts without
explanation. It can mean anything from "Stata complained"
to "Stata didn't produce the results I expected".

That said, some of your results are puzzling.

(B) is illegal, rather than ambiguous: Stata doesn't allow you to use
wildcards if an -if- condition in the way you would like.

But where is the problem coming with (A)? I can't reproduce that. Are you sure
that you are not bumping against the maximum number of variables
allowed with your Stata and your memory setting?
-egen, rowtotal()- itself should not break down given your size
of problem.

I can't comment on (C), as your report is in effect that you
find the result puzzling.

Nick
[email protected]

Kyra Naumoff Shields

> I am attempting to do some "simple" counting in Stata, but, thus far,
> I haven't been successful.
>
> My task is to sum frequencies of responses to time activity questions.
>  I have time activity information at 30 minute intervals over the
> better part of 2 days.
>
> For example, for household 1 (out of a total of 178 households),
> examples of my variables are:
> d1_04_00f   (day 1, 4am, status of fire)
> d1_04_30f   (day 1, 4:30 am, status of fire)
> d1_05_00f   (day 1, 5am, status of fire)
> etc.
>
> The codes for fire are 0=unlit, 1=fire in kitchen, or 2=fire outside.
> This example represents only a small portion of my dataset; I also
> have similarly coded questions corresponding to mother and child
> activities at 30 minute intervals.
*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index