楼主: kukudoudou
57468 30

[回归分析求助] 如何在bys :reg后继续预测yhat? [推广有奖]

21
胡文倩 发表于 2017-8-16 16:47:52
voodoo 发表于 2012-6-12 22:48
我做了一下,结果一样的!
// 方法一
egen t = group(year)
我用了您的命令,第一个回归成功了,但是再进行第二个回归时就显示“invalid syntax”,百思不得其解啊~希望您能帮我解答以下,
下面是我写的命令,
第一次回归:
egen t=group(year)
qui sum t
local Nt=r(max)
egen s=group(Indcd)
qui sum s
local Ns=r(max)
gen res=.
forvalues t=1/`Nt'{
  forvalues s=1/`Ns'{
    cap qui reg cfo aa sa sa1 sa2 if (t==`t'& s==`s')
        cap qui predict e if e(sample),res
        cap qui replace res=e if e(sample)
        cap drop e
  }
}
第二次回归:
qui sum t
local Nt=r(max)
qui sum s
local Ns=r(max)
gen res=.
forvalues t=1/`Nt'{
  forvalues s=1/`Ns'{
    cap qui reg cfo aa sa sa1 sa2 if (t==`t'& s==`s')
        cap qui predict e if e(sample),res
        cap qui replace res=e if e(sample)
        cap drop e
  }
}
结果显示 invalid syntax,这是为什么呢?

22
潇潇木枼 发表于 2017-10-17 21:03:39
请问为什么每次跑merge m:1 industry year using 123.dta 的时候总会出现master data not sorted?

23
90后村民Ing 发表于 2017-10-19 16:55:40
voodoo 发表于 2012-6-12 22:48
我做了一下,结果一样的!
// 方法一
egen t = group(year)
你好,我是刚学stata,分行业分年度回归// 方法一
egen t = group(year)
qui sum t
local Nt = r(max)
egen s = group(ind)
qui sum s
local Ns = r(max)
gen res = .
forvalues t = 1/`Nt' {
     forvalues s = 1/`Ns' {
        cap qui reg return returntl1 size if (t==`t' & s==`s')
        cap qui predict e if e(sample), res
        cap qui replace res = e if e(sample)
        cap drop e
   }
}中,gen res = .这一步res是什么意思?

24
黃河泉 在职认证  发表于 2017-10-19 17:57:00
潇潇木枼 发表于 2017-10-17 21:03
请问为什么每次跑merge m:1 industry year using 123.dta 的时候总会出现master data not sorted?
因该是路径 (path) 不同所导致的。

25
潇潇木枼 发表于 2017-10-20 15:04:39
黃河泉 发表于 2017-10-19 17:57
因该是路径 (path) 不同所导致的。
好像是主数据没有排序,我sort之后跑了就对了

26
黃河泉 在职认证  发表于 2017-10-21 08:01:29
潇潇木枼 发表于 2017-10-20 15:04
好像是主数据没有排序,我sort之后跑了就对了
OK,了解!错误讯息有提到 master data not sorted

27
小美哉 发表于 2018-3-20 22:05:42
想请问一下大家,为什么每次跑到statsby _b, by(hy year) saving(code.dta, replace): reg y x1 x2 x3 时都跑不出来,显示file code.dta could not be opened,是文件问题吗?我改为statsby _b, by(hy year) : reg y x1 x2 x3 时,又显示no; data in memory would be lost,到底是哪里出问题了呢?

28
黃河泉 在职认证  发表于 2018-3-21 06:58:16
小美哉 发表于 2018-3-20 22:05
想请问一下大家,为什么每次跑到statsby _b, by(hy year) saving(code.dta, replace): reg y x1 x2 x3 时都 ...
要不要先改一下档名,类似
  1. statsby _b, by(hy year) saving("b.dta", replace): reg y x1 x2 x3
复制代码

29
常涓 发表于 2018-11-26 15:56:29 来自手机
这个code.dta是即将要保存的另一个文档用来回归出yhat,自己随便命名一个对吗?

30
常涓 发表于 2018-11-26 16:34:11 来自手机
kukudoudou 发表于 2012-4-6 12:44
第一步是分年份和分行业做回归
bys industry year:reg y x1 x2 x3 x4
然后我希望可以得到预测值,但是如 ...
这结果是啥意思,那个123.dta到底是个什么东西,求指导

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-20 07:28