Dear all,
My data set is of housing prices in a city. I will call this data "sales data set." The unit of analysis is a housing unit being sold. And the data set has a district ID variable(D_id), year, month, and the dependent variable of interest (Y). The year and month information indicate the time of a house being sold. The number of observations is 872.
D_id year month Y
a 2012 3 70.2
a 2015 6 55.6
b 2013 5 44.5
b 2013 11 23.5
c 2013 2 11.4
c 2013 7 41.5
c 2013 7 82.0
c 2013 9 50.5
c 2014 11 21.1
...
And I have another data set, which contains the average housing price(AP) for all the districts and all months. I will call it "city data set." The years are from 2011 to 2016. The number of observation is 57,239. The number of district is 1,031.
D_id year month AP
a 2011 1 23.4
a 2011 2 35.6
a 2011 3 99.8
a 2011 4 60.4
a 2011 5 70.2
a 2011 6 55.6
a 2011 7 23.4
a 2011 8 35.6
a 2011 9 99.8
a 2011 10 60.4
a 2011 11 70.2
a 2011 12 55.6
a 2012 1 23.4
a 2012 2 35.6
a 2012 3 99.8
a 2012 4 60.4
a 2012 5 70.2
a 2012 6 55.6
a 2012 7 23.4
...
My goal is to calculate the 3-month, 6-month, 9-month, and 12-month moving averages before 1 month for a housing unit sold using the city data set. For example, as for the first observation in the sales data set, I have to calculate the 3-month moving average of the district a's average housing prices from 2010.12 to 2011.2 by using the city data set. For the 6-month moving average, I have to calculate it from 2010.9 to 2011.2 for the district a. Then, I have to merge these moving average variables onto the sales data set.
I am trying to solve this problem for a couple of days, but I am failing. I hope this problem interests you, and experts in Stata programming could provide some help and advice.
Thank you very much.
Sincerely,
Tony Yoon
My data set is of housing prices in a city. I will call this data "sales data set." The unit of analysis is a housing unit being sold. And the data set has a district ID variable(D_id), year, month, and the dependent variable of interest (Y). The year and month information indicate the time of a house being sold. The number of observations is 872.
D_id year month Y
a 2012 3 70.2
a 2015 6 55.6
b 2013 5 44.5
b 2013 11 23.5
c 2013 2 11.4
c 2013 7 41.5
c 2013 7 82.0
c 2013 9 50.5
c 2014 11 21.1
...
And I have another data set, which contains the average housing price(AP) for all the districts and all months. I will call it "city data set." The years are from 2011 to 2016. The number of observation is 57,239. The number of district is 1,031.
D_id year month AP
a 2011 1 23.4
a 2011 2 35.6
a 2011 3 99.8
a 2011 4 60.4
a 2011 5 70.2
a 2011 6 55.6
a 2011 7 23.4
a 2011 8 35.6
a 2011 9 99.8
a 2011 10 60.4
a 2011 11 70.2
a 2011 12 55.6
a 2012 1 23.4
a 2012 2 35.6
a 2012 3 99.8
a 2012 4 60.4
a 2012 5 70.2
a 2012 6 55.6
a 2012 7 23.4
...
My goal is to calculate the 3-month, 6-month, 9-month, and 12-month moving averages before 1 month for a housing unit sold using the city data set. For example, as for the first observation in the sales data set, I have to calculate the 3-month moving average of the district a's average housing prices from 2010.12 to 2011.2 by using the city data set. For the 6-month moving average, I have to calculate it from 2010.9 to 2011.2 for the district a. Then, I have to merge these moving average variables onto the sales data set.
I am trying to solve this problem for a couple of days, but I am failing. I hope this problem interests you, and experts in Stata programming could provide some help and advice.
Thank you very much.
Sincerely,
Tony Yoon
Comment