Statalist


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

st: RE: AW: RE: Average for panel data


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: AW: RE: Average for panel data
Date   Thu, 16 Jul 2009 13:56:21 +0100

It does no harm and it may be crucial to spell out that within each
panel observations are to be time-sorted. 

Thus 

bys id (Year):

is safer than 

bys id:

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

Martin Weiss

My solution does extend to the panel case in exactly the fashion which
you
describe. Am I missing something else in your request?


********
clear*

input  id	Year	V1	 V2	V3   
1	1990	100	25	25
1	1991	500	60	12
1	1992	0	0	.
1	1993	.	.       .
1	1994	600	300	50 
2	1990	100	25	29
2	1991	500	60	13
2	1992	0	0	.
2	1993	.	.       .
2	1994	600	300	60 
end

compress
list, noobs  

bys id: gen newV3=/* 
 */ sum(V3)/sum(V3!=.)

list, noobs
********

SERGIO MOISES AFCHA CHAVEZ

Thanks for your fast response, but I think I explain my question badly:

In your solution:

gen newV3=sum(V3)/sum(V3!=.)

Sum (V3) is a sum of all observations, I have a panel data, so, the Id
variable
continue with 2,3....3500 and I need the average variable for every 
individual in my database. I think I could obtain this with: 

by id: gen newV3=sum(V3[_n])

But, I don't know how continue with that, I need to divide this between
the
number of the years with valid observation, and I don't know how express
this
with STATA. 

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