Statalist The Stata Listserver


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

st: RE: data management


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: data management
Date   Wed, 16 May 2007 11:55:58 +0100

Sounds like 

bysort hh firm time : replace value = sum(value) 
by hh firm time : replace value = value[_N] 

But this is safer: 

bysort hh firm time : gen sumvalue = sum(value) 
by hh firm time : replace sumvalue = sumvalue[_N] 

or 

egen sumvalue = total(value), by(hh firm time) 

Nick 
[email protected] 

Alexander Staus
 
> I want to combine different observations in a panel dataset. 
> e.g. for hh 72 (=id) I want to sum 
> the variable "value" if the firm is the same on one date, but 
> other variables just stay as they 
> are.
> 
> From observations 15 and 16 I want to replace these 
> observations by a new one with that 
> date (=04mar2006), firm is unchanged at 1, value is summed 
> (=92+149=241), child and 
> height stay unchanged.
> 
> --------------------------------------------------------
> obs	hh    time                firm  value   child   height
> 13.	72   08feb2006         4    441        1      3 
> 14.	72   14feb2006         2     59        1      3 
> 15.	72   04mar2006         1     92        1      3 
> 16.	72   04mar2006         1    149        1      3 
> 17.	72   08mar2006         4    213        1      3 
> 	--------------------------------------------------
> 18.	72   16mar2006         1    453        1      3 
> 19.	72   16mar2006         1     92        1      3 
> 20.	72   16mar2006         4    259        1      3 
> 21.	72   20mar2006         1     79        1      3 
> 22.	72   24mar2006         4    295        1      3 
> 	--------------------------------------------------
> 23.	72   30mar2006         4    279        1      3 
> 24.	72   04apr2006         1    111        1      3 
> 25.	72   24apr2006         1     99        1      3 
> --------------------------------------------------------
> 

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