以HildrethandLu(1960)对冰淇淋需求函数的研究为例,数据集为icecream.dta包含下列变量的30个月度时间序列数据:consumption(人均冰淇淋消费量),income(平均家庭收入),price(冰淇淋价格),temp(平均华氏气温),time(时间)。目的:研究冰淇淋消费数量的影响因素。首先画折线图,观察各变量与因变量之间的大致关系:graphtwowayconnectedconsumptiontime||connectedtemp100time||connectedpricetime||connectedincometime,yaxis(2)建立回归模型;进行OLS回归得到:_cons.1973149.27021610.730.472-.3581223.752752temp.0034584.00044557.760.000.0025426.0043743income.0033078.00117142.820.009.0008999.0057156price-1.044413.834357-1.250.222-2.759458.6706322consumptionCoef.Std.Err.tP|t|[95%Conf.Interval]Total.12552335829.004328392RootMSE=.03683AdjR-squared=0.6866Residual.03527283526.001356647R-squared=0.7190Model.0902505233.030083508ProbF=0.0000F(3,26)=22.17SourceSSdfMSNumberofobs=30.regconsumptionpriceincometemp估计结果显示,气温与收入均显著,而价格和常数不显著。由于这是时间序列数据,我们怀疑其扰动项存在自相关。先画残差与滞后值的散点图-.1-.050.05.1-.1-.050.05.1ResidualslreFittedvalues从散点图看可能存在正相关。画自相关与偏相关图-0.500.000.50Autocorrelationsofre051015LagBartlett'sformulaforMA(q)95%confidencebands-1.00-0.500.000.50Partialautocorrelationsofre051015Lag95%Confidencebands[se=1/sqrt(n)]自相关图不明显,偏相关图显示了1阶与10阶之后的高阶自相关。进行BG检验与Q检验,先设定10阶滞后。Probchi2(10)=0.0895Portmanteau(Q)statistic=16.3718Portmanteautestforwhitenoise.wntestqre,lags(10)H0:noserialcorrelation1014.977100.1329lags(p)chi2dfProbchi2Breusch-GodfreyLMtestforautocorrelation.estatbgodfrey,lags(10)10阶自相关不存在,因为要检验1阶自相关,所以先设定2阶滞后检验。不存在2阶自相关,最后检验1阶自相关Probchi2(2)=0.1616Portmanteau(Q)statistic=3.6450Portmanteautestforwhitenoise.wntestqre,lags(2)H0:noserialcorrelation24.48720.1061lags(p)chi2dfProbchi2Breusch-GodfreyLMtestforautocorrelation.estatbgodfrey,lags(2)Probchi2(1)=0.0578Portmanteau(Q)statistic=3.6000Portmanteautestforwhitenoise.wntestqre,lags(1)H0:noserialcorrelation14.23710.0396lags(p)chi2dfProbchi2Breusch-GodfreyLMtestforautocorrelation.estatbgodfrey,lags(1)存在1阶自相关。如果用Newey-West方法进行估计,则指定滞后阶数1阶与原估计相比,估计系数相等,系数以及模型整体显著性几乎没变。如果只是追求系数的一致性且在大样本下,可以到此为止。但此例为一阶自相关,可以用FGLS进行估计。_cons.1973149.29643940.670.512-.4120249.8066547temp.0034584.00046477.440.000.0025033.0044136income.0033078.00120652.740.011.0008278.0057877price-1.044413.8874727-1.180.250-2.868639.7798132consumptionCoef.Std.Err.tP|t|[95%Conf.Interval]Newey-WestProbF=0.0000maximumlag:1F(3,26)=18.76RegressionwithNewey-WeststandarderrorsNumberofobs=30.neweyconsumptionpriceincometemp,lag(1)使用PW方法进行估计:Durbin-Watsonstatistic(transformed)1.846795Durbin-Watsonstatistic(original)1.021169rho.8002264_cons.5870049.29526991.990.057-.01993111.193941temp.0029541.00071094.160.000.0014929.0044152income-.0008022.0020458-0.390.698-.0050074.0034029price-1.048854.759751-1.380.179-2.610545.5128361consumptionCoef.Std.Err.tP|t|[95%Conf.Interval]Total.07210031529.002486218RootMSE=.03232AdjR-squared=0.5799Residual.02715435426.001044398R-squared=0.6234Model.044945963.014981987ProbF=0.0000F(3,26)=14.35SourceSSdfMSNumberofobs=30Prais-WinstenAR(1)regression--iteratedestimates使用CO方法估计:Durbin-Watsonstatistic(transformed)1.548837Durbin-Watsonstatistic(original)1.021169rho.4009256_cons.1571479.28962920.540.592-.4393546.7536504temp.0035584.00055476.420.000.002416.0047008income.0032027.00154612.070.049.0000186.0063869price-.8923963.8108501-1.100.282-2.562373.7775807consumptionCoef.Std.Err.tP|t|[95%Conf.Interval]Total.07249249128.002589018RootMSE=.03191AdjR-squared=0.6068Residual.02545189425.001018076R-squared=0.6489Model.0470405963.015680199ProbF=0.0000F(3,25)=15.40SourceSSdfMSNumberofobs=29Cochrane-OrcuttAR(1)regression--iteratedestimates从估计系数来看,PW法估计原先显著的income变为不显著,CO法估计的显著性与Newey-West方法一致,且从e’e/(n-k)来看CO法要比PW法略好一些。自相关可能是遗漏变量造成的,因此可以加入变量的滞后值做自变量进行回归。考虑到这个模型,消费、温度、收入、价格均很有可能是自相关的变量,如果这些自相关变量的滞后值会影响消费,而我们遗漏了,那么必然会导致自相关,所以我们加入所有这些变量的一阶滞后进行回归。_cons.0113797.25437010.040.965-.5176119.5403713L1.-.0021416.0007266-2.950.008-.0036525-.0006306tempL1..0038767.00197731.960.063-.0002354.0079887incomeL1..6409404.77585740.830.418-.97254332.254424priceL1..2239369.25173450.890.384-.2995735.7474474consumptiontemp.0044129.00095424.620.000.0024286.0063973income-.0011027.0020689-0.530.600-.0054053.0031999price-.9320616.7353747-1.270.219-2.461357.5972339consumptionCoef.Std.Err.tP|t|[95%Conf.Interval]Total.12479323228.004456901RootMSE=.0286AdjR-squared=0.8165Residual.01717714721.000817959R-squared=0.8624Model.1076160857.015373726ProbF=0.0000F(7,21)=18.80SourceSSdfMSNumberofobs=29.regconsumptionpriceincometempL.consumptionL.priceL.incomeL.temp有一些滞后项显著有一些不显著,但是我们还不能马上根据t检验判断哪些滞后项需要删除,因为可能存在自相关导致t检验不可信。所以我们要首先进行自相关检验。以下是BG检验的结果可以看出加入滞后变量很好地排除了自相关。所以我们可以相信t检验的结果,把那些不显著的滞后值都剔除重新进行估计10.77710.3779lags(p)chi2dfProbchi2Breusch-GodfreyLMtestforautocorrelation.estatbgodfrey,lags(1)ProbF=0.5245F(2,21)=0.67(2)L.price=0(1)L.consumption=0.test(L.consumption=0)(L.price=0)L1.-.0018911.000671-2.820.010-.0032759-.0005063tempL1..0039447.00186092.120.045.000104.0077855incometemp.0050321.00064097.850.000.0037094.0063548income-.0003117.0019099-0.160.872-.0042534.0036301price-.3817436.2707818-1.410.171-.9406098.1771226consumptionCoef.Std.Err.tP|t|[95%Conf.Interval]Total3.8522970229.13283