Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: AW: preserving missing values when using total


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: AW: preserving missing values when using total
Date   Sun, 8 Mar 2009 19:03:31 -0000

-update- your Stata. This -missing- option was added in Stata 10.1. (That was a good reason for me not to mention this solution in the 2005 posting you mentioned.) 

The FAQ underlines that 10.1 is the current version and that you should make it clear if you are using an earlier version. 

If an -update- is impossible for you now, as you are not sysadmin, it can be done otherwise. You said that you knew that in your first post! 

bysort year (accounts) : gen accounts_total = sum(accounts) 
by year : replace accounts_total = /// 
	cond(missing(accounts[1]), ., accounts_total[_N]) 

Nick 
n.j.cox@durham.ac.uk 

Srini

STATA is giving me an error saying that I'm not allowed to use the option missing with egen/total.

I'm using version 10 - is there another command I can try?

--- On Sun, 3/8/09, Martin Weiss <martin.weiss1@gmx.de> wrote:

> by year, sort : egen float accounts_total =
> total(accounts), missing

Srini
 
> After data manipulation, I have a data set with multiple
> observations per
> year. I used total to sum over these observations to get
> collapse the data,
> but realized that the process was replacing missing values
> with zeroes.
> 
>             year   
> accounts       accounts_total
> district 1  72     
>    .           
>      0
> district 1  72     
>    .           
>      0
> district 1  72     
>    .           
>      0
> district 1  72     
>    .           
>      0
> district 1  73     
>    .           
>      0
> district 1  73     
>    .           
>      0
> district 1  73     
>    .           
>      0
> district 1  74        10 
>            
>    34
> district 1  74        20 
>            
>    34
> district 1  74     
>    4           
>      34
> district 1  75     
>    15         
>       32
> district 1  75     
>    17         
>       32
> 
> In my case, accounts data is missing for the first few
> years. How can I
> ensure that when I take the total by year, accounts_total =
> . for year = 72
> and year = 73? Currently, STATA has accounts_total = 0 for
> those years.
> 
> If there isn't a specific command, I can try and use the
> method suggested by
> Nick Cox in 2005 in this thread: Egen functions -
> preserving missing values?

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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