Hello, I am setting up a synthetic control based on data that looks something like this:
cityid | yearquarter | year | rent
1 | 2010q1 | 2010 | 40
1 | 2010q2 | 2010 | 42
1 | 2010q3 | 2010 | 41
1 | 2010q4 | 2010 | 40
2 | 2010q1 | 2010 | 39
2 | 2010q2 | 2010 | 36
2 | 2010q3 | 2010 | 22
2 | 2010q4 | 2010 | 33
1 | 2011q1 | 2011 | 45
1 | 2011q2 | 2011 | 46
1 | 2011q3 | 2011 | 45
1 | 2011q4 | 2011 | 44
2 | 2011q1 | 2011 | 30
2 | 2011q2 | 2011 | 32
2 | 2011q3 | 2011 | 33
2 | 2011q4 | 2011 | 31
I would like to create variables that summarize "rent" by city FOR a specific year -> e.g. create a new variable "avgrent_2010" that is the average 2010 rent in each city. These variables are pre-intervention levels of my outcome variable that will be used in my synthetic control as predictor variables. Ideally, the data would look like the following:
cityid | yearquarter | year | rent | avgrent_2010
1 | 2010q1 | 2010 | 40 | 40.75
1 | 2010q2 | 2010 | 42 | 40.75
1 | 2010q3 | 2010 | 41 | 40.75
1 | 2010q4 | 2010 | 40 | 40.75
2 | 2010q1 | 2010 | 39 | 32.5
2 | 2010q2 | 2010 | 36 | 32.5
2 | 2010q3 | 2010 | 22 | 32.5
2 | 2010q4 | 2010 | 33 | 32.5
1 | 2011q1 | 2011 | 45 | 40.75
1 | 2011q2 | 2011 | 46 | 40.75
1 | 2011q3 | 2011 | 45 | 40.75
1 | 2011q4 | 2011 | 44 | 40.75
2 | 2011q1 | 2011 | 30 | 32.5
2 | 2011q2 | 2011 | 32 | 32.5
2 | 2011q3 | 2011 | 33 | 32.5
2 | 2011q4 | 2011 | 31 | 32.5
Thus far, I have used:
egen rent2010=mean(rent)if year==2010, by(cityid)
Which gives me:
cityid | yearquarter | year | rent | avgrent_2010
1 | 2010q1 | 2010 | 40 | 40.75
1 | 2010q2 | 2010 | 42 | 40.75
1 | 2010q3 | 2010 | 41 | 40.75
1 | 2010q4 | 2010 | 40 | 40.75
2 | 2010q1 | 2010 | 39 | 32.5
2 | 2010q2 | 2010 | 36 | 32.5
2 | 2010q3 | 2010 | 22 | 32.5
2 | 2010q4 | 2010 | 33 | 32.5
1 | 2011q1 | 2011 | 45 | .
1 | 2011q2 | 2011 | 46 | .
1 | 2011q3 | 2011 | 45 | .
1 | 2011q4 | 2011 | 44 | .
2 | 2011q1 | 2011 | 30 | .
2 | 2011q2 | 2011 | 32 | .
2 | 2011q3 | 2011 | 33 | .
2 | 2011q4 | 2011 | 31 | .
How can I generate a variable that is a summary of a specific subset of data within a group (year AND cityid) but apply it to all observations that meet only one of those criteria (cityid)?
Thanks in advance for any help!
Related Posts with Generating summarized variables for synthetic control predictors
Visualizing an interaction termDear Statalist, I have just recently started using Stata, so this might be a rookie question. I ha…
Replacing multiple values, with the same conditionHi All, Although the -replace- command is fairly intuitive, it is sometimes a bit tricky. Specific…
weighted transition matrixHello, I am working with a household survey panel data. I have weights (not integer, time varying) …
Question on oneway anova and pairwise comparisonRecently, I'm conducting research, we would like to see some difference between different national i…
Accident Count Panel Data ModelHi, I am new to Stata and this forum. I am trying to find the effect of changes in fuel price on ro…
Subscribe to:
Post Comments (Atom)
0 Response to Generating summarized variables for synthetic control predictors
Post a Comment