# Re: st: monthly means & CI

 From Ana Gabriela Guerrero Serdan To statalist@hsphsun2.harvard.edu Subject Re: st: monthly means & CI Date Tue, 13 Mar 2007 11:42:59 -0700 (PDT)

```Dear Nicholas,

Thanks, yes collapse is an option but I want to
calculate means and CI for each month not for the
whole period if I use collapse then I can not use ci.
Or this  is also possible?

I think that if I first create a unique value for each
month then I could be able to use e.g.
by monthnumber: ci female

so if my data looks like:

list month year female total

+-------------------------------+
| month   year   female   total |
|-------------------------------|
1. |     1   2006        0       1 |
2. |     1   2006        0       1 |
3. |     1   2004        0       1 |
4. |     1   2006        0       1 |
5. |     1   2006        0       1 |
|-------------------------------|
6. |     1   2006        0       1 |
7. |     1   2005        0       1 |
8. |     1   2004        0       1 |
9. |     1   2005        0       1 |
10. |     1   2005        0       1 |
|-------------------------------|
11. |     1   2006        0       1 |
12. |     1   2005        0       1 |
13. |     1   2006        0       1 |
14. |     1   2004        0       1 |
15. |     1   2006        0       1 |
|-------------------------------|

and then I want to create a unique value for month per
year, so the new variable would take value of 1,2,3
according to the month and year.

this is where i get stuck:

I have tried:

1) by year month, sort: gen monthly_num=_n

this doesnt work.

and this
2)

. sort year month

. egen Monthly_num = group(month year)

this works but now I cannnot know which month
corresponds to the Monthly_num although I do get the
total number of monthsyear.

+------------------------------------------+
| month   year   female   total   Monthl~m |
|------------------------------------------|
1. |     3   2003        0       1          7 |
2. |     3   2003        0       1          7 |
3. |     3   2003        0       1          7 |
4. |     3   2003        0       1          7 |

as you see the first values of Monthly_num take=7 and
should be 1.

Anyone can help?

--- Clive Nicholas <crazeeclive@yahoo.co.uk> wrote:

> Gaby Serdan wrote:
>
> I have data on deaths. I need to calculate the mean
> &
> CI of females in proportion to all population. Im
> trying first to create a variable for each month
> then
> take the total number of female per month and then
> divide by total number of deaths per month.
>
> [...]
>
> Im somehow lost, since my data is per individula.
> should I create a different dataset with montly
> deaths
> only or can I calculate means and confidence
> intervals
> in this same dataset.
>
>
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> My suggestion would be to do the following (after
> -input-ing the data and variables that you show):
>
> . collapse (sum) female male sex_unknown, by(month
> year)
>
> The -count- variable seemed to me to be a bit of a
> red herring in getting what you wanted, so I
> dispensed with this. Since only one female appears
> in this snapshot of your data, I created
> the variable -prop- which records the monthly
> proportion of those who
> died where their sex is unknown.
>
> . g total=female+male+sex_unknown
>
> . g prop=sex_unknown/total
>
> . sum prop, detail
>
>                             prop
>
-------------------------------------------------------------
>       Percentiles      Smallest
>  1%          .25            .25
>  5%          .25             .5
> 10%           .5              1       Obs
>       15
> 25%            1              1       Sum of Wgt.
>       15
>
> 50%            1                      Mean
> .9166667
>                         Largest       Std. Dev.
> .2249339
> 75%            1              1
> 90%            1              1       Variance
> .0505952
> 95%            1              1       Skewness
> -2.346011
> 99%            1              1       Kurtosis
>  6.82526
>
> . display .9166667-(.2249339*1.96)
>
> .47579626
>
> . display .9166667+(.2249339*1.96)
> 1.3575371
>
> I guess you'd need to define which confidence
> interval you're looking for. The percentiles don't
> look very informative, and both subtracting and
> adding 1.96 times the standard deviation to and from
> the mean (assuming a 95% CI) gives you an upper
> confidence limit above 1, which makes little sense.
> However, applying this to all of your data might
> yield more sensible statistics.
>
> Hope all that helps.
>
> Clive Nicholas
>
>
>
>
>
>
>
>
>
___________________________________________________________
>
> New Yahoo! Mail is the ultimate force in competitive
> emailing. Find out more at the Yahoo! Mail
> Championships. Plus: play games and win prizes.
>
http://uk.rd.yahoo.com/evt=44106/*http://mail.yahoo.net/uk
>
>
> *
> *   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/
>

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