楼主: nkzhh
108029 142

[程序分享] 用stata如何检验panel的自相关和异方差   [推广有奖]

31
lyrasover 发表于 2007-8-20 19:30:00
找到了,用findit xtserial搜一下就行了

32
蜻蜓点水 发表于 2007-8-21 13:59:00

excellent questions asked. the following codes which is I used in my research provide those two tests for panel data. hope it helps


1. /*****wooldridge test for first order autocorrelation****/
tsset county year, yearly
findit xtserial
net sj 3-2 st0039
net install st0039
xtserial y x1 x2 x3 x4 x5


2. /**** LR test for heteroscedasticity ******/
xtgls y x1 x2 x3 x4 x5, i(country) t(year) igls panels(heteroskedastic)
estimates store hetero
xtgls y x1 x2 x3 x4 x5, i(country) t(year)
estimates store nohetero
local df=e(N_g)-1
lrtest hetero nohetero , df(`df')

33
mangmang 发表于 2007-8-22 05:24:00

谢谢蜻蜓点水!!有个疑问,如果检验得知有异方差及自相关,应该如何纠正?理论上说是要用feasible generalized least squares (FGLS) ,就是用你提供的命令xtgls和igsl么?

而且在这个命令xtgls y x1 x2 x3 x4 x5, i(country) t(year) igls panels(heteroskedastic)中的i(country) 和t(year)要提供数据么?举例我有10个国家,6年数据,我要在i(美国,英国,法国等等)t(92 93 94 95 96 97)么?谢谢!

34
蜻蜓点水 发表于 2007-8-22 14:40:00

Change your country to numbers first. The following is an example. Your data should look like the following sample. Once you found the problems of heteroscedasticity and autocorrelation using the tests provided, then it will be proper to use FGLS using the following STATA command:


iis country
tis year
xtgls y x1 x2 x3, i(country) t(year) panels(correlated) corr(psar1)

This code corrects for heteroscedasticity across sections (or countries), it corrects for autocorrelation within countries (serial correlation) and contemporaneous correlation (spatial correlation) between countries as well. It is similar (but not exactly same) to Parks’ method in SAS.

Data format

Country year x1 x2 x3
1 1 x x x
1 2 x x x
2 1 x x x
2 2 x x x
3 1 x x x
3 2 x x x

[此贴子已经被作者于2007-8-22 15:29:55编辑过]

35
mangmang 发表于 2007-8-23 04:48:00

奇怪,state总提示我这个问题,

"year is not regularly spaced or does not have intervals of 1 -- use
the force option to treat the intervals as though they were regular"

我数据的形式跟你给的是一样的呀,只是我作回归的时候,多了industry specific time trend (dummy variables)

36
蜻蜓点水 发表于 2007-8-23 05:11:00
i dont know at this point. you may need reexamine your panel (say, sorted your data by country first and then year and then use force option). Again. not sure.

37
mangmang 发表于 2007-8-23 13:19:00
Anyway, thanks again

38
唐伯小猫 发表于 2007-8-28 18:16:00

请问各位牛人大大

如果有自相关和异方差的话,用什么命令纠正呢?

谢谢

心若向阳,无畏悲伤。

39
蜻蜓点水 发表于 2007-8-29 02:27:00
"xtgls y x1 x2 x3, i(country) t(year) panels(correlated) corr(psar1)

This code corrects for heteroscedasticity across sections (or countries), it corrects for autocorrelation within countries (serial correlation) and contemporaneous correlation (spatial correlation) between countries as well. It is similar (but not exactly same) to Parks’ method in SAS."

40
唐伯小猫 发表于 2007-8-29 02:38:00

谢谢楼上!我的数据是panel data,我只用fixed effect model.

我测试过了,我的模型里面没有自相关的问题

但是存在异方差的问题。

现在的问题是,用xtreg估计后,测试结果有异方差,想纠正的话,用xtgls命令就可以了么?

心若向阳,无畏悲伤。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-25 04:42