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
marginscontplot problem.Dear All, I have a dataset with two variables (simplified). The basic statistics Code: . sum indep…
Estimating Productivity from Cobb Douglas and Variables Significance changeI am trying to find impact of (Dividends) on (Firm Sales) controlling for the firm characteristics i…
How to create a formlacode year var2 top5 1100 201712 5 1 1100 201712 5 2 1100 201712 5 3 1100 201712 4.9 4 1100 201712 4.…
Clean syntax in STATAhi, please help me! I found command that is not recognized in STATA14 but is used in Chaney2012 pape…
Estimating Productivity adnI am trying to find impact of (Dividends) on (Firm Sales) controlling for the firm characteristics i…
Subscribe to:
Post Comments (Atom)
0 Response to Generating summarized variables for synthetic control predictors
Post a Comment