全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
16313 8
2012-05-08
如题。本人想根据受教育年数分别作回归  受教育年数一共是17年  运气比较好  万一是50年呢  那我气不死要弄50个回归。。。想想都可怕,此外,做完每一个回归后,保存suppins变量的系数,并赋值到b0变量中,也就是有17个suppins系数值。这一步我怎么循环都无法实现  无奈使用最老土的方式实现的,我的stata命令如下:
  quietly regress ltotexp suppins phylim actlim totchr age female income if   educyr==0
  gen b0=_b[suppins]
   quietly regress ltotexp suppins phylim actlim totchr age female income if   educyr==1
   replace b0=_b[suppins] if educyr==1
   quietly regress ltotexp suppins phylim actlim totchr age female income if   educyr==2
      replace b0=_b[suppins] if   educyr==2
  quietly  regress ltotexp suppins phylim actlim totchr age female income if   educyr==3
     replace b0=_b[suppins]  if   educyr==3
  quietly  regress ltotexp suppins phylim actlim totchr age female income if   educyr==4
     replace b0=_b[suppins] if   educyr==4
   quietly regress ltotexp suppins phylim actlim totchr age female income if   educyr==5
      replace b0=_b[suppins] if   educyr==5
   quietly regress ltotexp suppins phylim actlim totchr age female income if   educyr==6
      replace b0=_b[suppins] if   educyr==6
   quietly regress ltotexp suppins phylim actlim totchr age female income if   educyr==7
      replace b0=_b[suppins] if   educyr==7
   quietly regress ltotexp suppins phylim actlim totchr age female income if   educyr==8
      replace b0=_b[suppins] if   educyr==8
   quietly regress ltotexp suppins phylim actlim totchr age female income if   educyr==9
      replace b0=_b[suppins] if   educyr==9
  quietly regress ltotexp suppins phylim actlim totchr age female income if   educyr==10
     replace b0=_b[suppins] if   educyr==10
    quietly regress ltotexp suppins phylim actlim totchr age female income if   educyr==11
    replace b0=_b[suppins] if   educyr==11
    quietly regress ltotexp suppins phylim actlim totchr age female income if   educyr==12
    replace b0=_b[suppins] if   educyr==12
    quietly regress ltotexp suppins phylim actlim totchr age female income if   educyr==13
    replace b0=_b[suppins] if   educyr==13
    quietly regress ltotexp suppins phylim actlim totchr age female income if   educyr==14
    replace b0=_b[suppins] if   educyr==14
    quietly regress ltotexp suppins phylim actlim totchr age female income if   educyr==15
    replace b0=_b[suppins] if   educyr==15
   quietly regress ltotexp suppins phylim actlim totchr age female income if   educyr==16
      replace b0=_b[suppins] if   educyr==16
     quietly regress ltotexp suppins phylim actlim totchr age female income if   educyr==17
    replace b0=_b[suppins] if   educyr==17

这种写法太坑爹了。。。请教高手帮我改进下吧  万一我哪天遇上了分年度分行业做回归,并保存变量系数值,岂不是直接无语到家了。。。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2012-5-8 15:17:41
for(i=0;i<17;i++)
{
    if educyr==i
         replace b0=.......
}
不知道你用的是什么语法
写道这里你应该有思路了吧
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-5-8 15:46:35
bobsport168 发表于 2012-5-8 15:17
for(i=0;i
我之前也尝试用循环的。。使用的是forvalue语句:
forvalue i=0/17{
            regress ltotexp suppins phylim actlim totchr age female income if   educyr==`i'
                        gen b0=_b[suppins]
                        replace b0=_b[suppins] if  educyr==`i'
                        }
就是搞不出来,你的语句我是看明白了  不过怎么多次回归后并保存每次系数值,还是不太懂
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-5-8 16:08:46
在for循环结束的同时把 i 赋值给一个变量 j,然后对j进行处理,当然j要事先定义,不知道我说的是不是你说的保存意思,不知道你的这个语法里有没有变量类型区分一说,你在代码中写道educyr==`i',而for循环中的i是数值类型的,不知道会不会影响。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-5-8 16:22:07
直接把所有结果导出来算了

bysort educyr:    ///
outreg2 using d:\temp\myfile, replace see:     ///
regress ltotexp suppins phylim actlim totchr age female income
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-5-8 18:44:09
statsby b0=_b[suppins], clear by(educyr): reg  ltotexp suppins phylim actlim totchr age female income

*已经是超高频帖了
https://bbs.pinggu.org/thread-1018129-1-1.html
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群