Hello all,
I am quite new to stata and I need help with a simple question (I think), that I just can't figure out. I am attempting to add the values in the count variable, so that I end up with unique values on year. Count refers to the number of events I am analyzing. So 1 menas that it happened once, 0 that the event did not occur that year. My dataset looks like this:
count year
1 1990
1 1992
1 1992
1 1993
1 1994
1 1995
1 1995
1 1995
1 1995
1 1996
1 1996
1 1996
1 1997
1 1998
1 2000
1 2000
1 2001
1 2001
1 2007
0 2008
1 2008
0 2009
1 2011
1 2014
1 2014
I wish to sum the count for each year, so that the dataset will look like this:
count year
1 1990
2 1992
1 1993
1 1994
4 1995
3 1996
1 1997
1 1998
2 2000
2 2001
1 2007
1 2008
0 2009
1 2011
2 2014
I then wish to "fill in the gaps", so that my dataset looks like this:
1 1990
0 1991
2 1992
1 1993
1 1994
4 1995
3 1996
1 1997
1 1998
0 1999
2 2000
1 2001
0 2002
0 2003
0 2004
0 2005
0 2006
1 2007
1 2008
0 2009
0 2010
1 2011
0 2012
0 2013
2 2014
I need to expand the dataset as I am going to include more variables where there will be values for every year.
All help is appreciated!
Regards,
Madeleine
Related Posts with Collapsing time variable
Marginal effects Tobit (mfx vs margins)Hello I'm trying to calculate the marginal effects of a Tobit model using the margins command instea…
Residuals in a panel data modelHi I am running a regression (using panel data) looking at the effect of income on food consumption …
Longitudinal data - generating variables dependent on observations within each subjectHi everyone, I have longitudinal data (see dataex below). I need to censor each id according to a f…
Help with using expand>2 while replacing values in duplicates generatedHi, I am trying to use the expand command to create duplicates and replacing one of the variables i…
Adding an interaction term into a model or stratifying data , which method is more preferable to analyse interaction terms?Hi Statlists, Hope this post finds you well. May I know why stratification seems to be less prefera…
Subscribe to:
Post Comments (Atom)
0 Response to Collapsing time variable
Post a Comment