将季度时间序列数据转换为月度数据

时间:2015-08-16 20:10:40

标签: r excel time-series stata data-conversion

我试图在月度住房数据上使用季度价格平减指数。你能帮我把季度数据转换成月度数据吗?我研究了在Stata中使用Cubic Spline Interpolation方法但是没有运气让do文件工作。我可以访问excel和R,所以这些都是我尝试的选项。感谢您的时间。

Quarterly       CPI Deflator Data    
1999-04-01  79.891
1999-07-01  80.180
1999-10-01  80.547
2000-01-01  81.163
2000-04-01  81.623
2000-07-01  82.152
2000-10-01  82.593
2001-01-01  83.112
2001-04-01  83.699
2001-07-01  83.973
2001-10-01  84.227
2002-01-01  84.497
2002-04-01  84.812
2002-07-01  85.190
2002-10-01  85.651
2003-01-01  86.179
2003-04-01  86.455
2003-07-01  86.934
2003-10-01  87.346
2004-01-01  88.108
2004-04-01  88.875
2004-07-01  89.422
2004-10-01  90.049
2005-01-01  90.883
2005-04-01  91.543
2005-07-01  92.399
2005-10-01  93.100
2006-01-01  93.832
2006-04-01  94.587
2006-07-01  95.247
2006-10-01  95.580
2007-01-01  96.654
2007-04-01  97.194
2007-07-01  97.531
2007-10-01  97.956
2008-01-01  98.516
2008-04-01  98.995
2008-07-01  99.673
2008-10-01  99.815
2009-01-01  100.062
2009-04-01  99.895
2009-07-01  99.873
2009-10-01  100.169
2010-01-01  100.522
2010-04-01  100.968
2010-07-01  101.429
2010-10-01  101.949
2011-01-01  102.399
2011-04-01  103.145
2011-07-01  103.768
2011-10-01  103.917
2012-01-01  104.466
2012-04-01  104.943
2012-07-01  105.508
2012-10-01  105.935
2013-01-01  106.363
2013-04-01  106.623
2013-07-01  107.128
2013-10-01  107.589
2014-01-01  108.009
2014-04-01  108.606
2014-07-01  109.044
2014-10-01  109.067
2015-01-01  109.099
2015-04-01  109.650


    Monthly Data    Monthly datapoint
1999-01-01  76.841
1999-02-01  79.863
1999-03-01  81.245
1999-04-01  78.911

1 个答案:

答案 0 :(得分:2)

使用末尾显示的Lines,将Lines的输入读入动物园对象zd,(或使用read.zoo("myfile.dat", header = TRUE)从文件中读取)。然后计算"yearmon"类月tt的序列,进行插值并使用na.spline进行插值。 (如果需要线性插值,则可以使用na.approx代替na.spline。)

library(zoo)
zd <- read.zoo(text = Lines, header = TRUE)
tt <- as.yearmon(seq(start(zd), end(zd), "month"))
zm <- na.spline(zd, as.yearmon, xout = tt)

我们使用了这个输入:

Lines <- "Quarterly       CPI 
1999-04-01  79.891
1999-07-01  80.180
1999-10-01  80.547
2000-01-01  81.163
2000-04-01  81.623
2000-07-01  82.152
2000-10-01  82.593
2001-01-01  83.112
2001-04-01  83.699
2001-07-01  83.973
2001-10-01  84.227
2002-01-01  84.497
2002-04-01  84.812
2002-07-01  85.190
2002-10-01  85.651
2003-01-01  86.179
2003-04-01  86.455
2003-07-01  86.934
2003-10-01  87.346
2004-01-01  88.108
2004-04-01  88.875
2004-07-01  89.422
2004-10-01  90.049
2005-01-01  90.883
2005-04-01  91.543
2005-07-01  92.399
2005-10-01  93.100
2006-01-01  93.832
2006-04-01  94.587
2006-07-01  95.247
2006-10-01  95.580
2007-01-01  96.654
2007-04-01  97.194
2007-07-01  97.531
2007-10-01  97.956
2008-01-01  98.516
2008-04-01  98.995
2008-07-01  99.673
2008-10-01  99.815
2009-01-01  100.062
2009-04-01  99.895
2009-07-01  99.873
2009-10-01  100.169
2010-01-01  100.522
2010-04-01  100.968
2010-07-01  101.429
2010-10-01  101.949
2011-01-01  102.399
2011-04-01  103.145
2011-07-01  103.768
2011-10-01  103.917
2012-01-01  104.466
2012-04-01  104.943
2012-07-01  105.508
2012-10-01  105.935
2013-01-01  106.363
2013-04-01  106.623
2013-07-01  107.128
2013-10-01  107.589
2014-01-01  108.009
2014-04-01  108.606
2014-07-01  109.044
2014-10-01  109.067
2015-01-01  109.099
2015-04-01  109.650"