Hello All,
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.
I would like 1) to tabulate the number of 0s, 1s and 2s for each
household in my dataset, and 2) to store this information in a new
variable.
My approaches have been many, but none have worked.
A) I tried:
forvalues i = 4/22 {
2. egen fire0_`i' = rowtotal(d1*0f) if d1_0`i'_00f == 0
3. egen fire1_`i' = rowtotal(d1*0f) if d1_0`i'_00f == 1
4. egen fire2_`i' = rowtotal(d1*0f) if d1_0`i'_00f == 2
5. egen fire00_`i' = rowtotal(d2*0f) if d2_0`i'_00f == 0
6. egen fire11_`i' = rowtotal(d2*0f) if d2_0`i'_00f == 1
7. egen fire22 _`i'= rowtotal(d2*0f) if d2_0`i'_00f == 2
8. }
But too many variables were specified (r(103)).
B) I then tried:
egen fire0d1 = rowtotal(d1*f) if d1*f == 0
but the d1*f abbreviation was ambiguous; for this example, d1*f
represents the 41 variables that I would like Stata to examine, count
all the zeros and store this information in a new variable called
fire0d1.
C) Finally, I tried to more manually address the problem, but even
this didn't work because the rowtotal seemed to ignore my "if
statements". I know this because fire0d1=fire1d1=fire2d1 for each of
the individuals in my dataset.
egen fire0d1 = rowtotal(d1*f*) if d1_00_00f==0 | d1_04_00f==0 |
d1_04_30f==0 | d1_05_00f==0 | d1_05_30f==0 | d1_06_00f==0 |
d1_06_30f==0 | d1_07_00f==0 | d1_07_30f ==0 | d1_08_00f==0 |
d1_08_30f ==0 | d1_09_00f ==0 | d1_09_30f ==0 | d1_10_00f ==0 |
d1_10_30f ==0 | d1_11_00f ==0 | d1_11_30f ==0 | d1_12_00f ==0 |
d1_12_30f ==0 | d1_13_00f ==0 | d1_13_30f==0 | d1_14_00f==0 |
d1_14_30f==0 | d1_15_00f==0 | d1_15_30f ==0 | d1_16_00f ==0 |
d1_16_30f ==0 | d1_17_00f==0 | d1_17_30f ==0 | d1_18_00f==0|
d1_18_30f==0 | d1_19_00f==0| d1_19_30f ==0 | d1_20_00f ==0 |
d1_20_30f ==0 | d1_21_00f ==0 | d1_21_30f ==0 | d1_22_00f ==0 |
d1_22_30f ==0 | d1_23_00f ==0 | d1_23_30f==0
Any advice would be greatly appreciated.
Thanks in advance,
Kyra
--
Kyra Naumoff Shields, MS
PhD candidate
UC Berkeley - Environmental Health Sciences
140 Warren Hall #7360
Berkeley, CA 94720-7360
510.847.7948 (cell)
*
* 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/