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: add up variable / quantile
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: add up variable / quantile
Date
Tue, 29 Mar 2011 11:44:33 +0100
On Tue, Mar 29, 2011 at 11:30 AM, Scharnigg, Stan (Stud. SBE)
<[email protected]> wrote:
> Look at the help for -egen-. You want
>
> egen total_gross = total(gross), by(accountID)
> -----------
>
> Thank you, but I have some additional questions:
>
> A. I have data for 6 years (72 months). What if I want to add up the gross_performance for e.g the first 12 months. So, I guess I need to
> create different variables for different time periods, but I am not sure how to do that. One extensive possibility might be that I create a different dataset
> for every period, but I guess there might also be another solution
>
> accountID; gross_performance; date
> 1 -.1 jan_00
> 1 .2 febr_00
> 3 .1 jan_00
> 3 .1 febr_00
You can specify -if- on an -egen- command. Different summaries will in
general require new variables (but not new datasets).
> B. If I use egen total_gross = total(gross_performance), by(accountID) I get many duplicate values. In some cases I have
> 72 duplicate values. What is the best way to delete the duplicate values, so that they won't show up if I do some tests. I don't
> think that renaming them to "0" is an option then.
You can use
egen tag = tag(accountID)
and then add
... if tag
to commands to ensure that each summary is used once only. You cannot
delete (in Stata -drop-) without losing other information.
Alternatively, -collapse- will yield a reduced dataset with one
observation for each account.
*
* 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/