楼主: hqs00000
16371 8

[数据管理求助] 怎么才可以吧下面的命令用循环语句实现? [推广有奖]

  • 3关注
  • 39粉丝

VIP

随风而动

已卖:1124份资源

院士

59%

还不是VIP/贵宾

-

威望
2
论坛币
27640 个
通用积分
23.1002
学术水平
45 点
热心指数
67 点
信用等级
34 点
经验
52757 点
帖子
1738
精华
0
在线时间
5433 小时
注册时间
2008-3-11
最后登录
2025-12-16

楼主
hqs00000 在职认证  发表于 2012-5-8 15:01:29 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
如题。本人想根据受教育年数分别作回归  受教育年数一共是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

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

扫码加我 拉你入群

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

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

关键词:循环语句 regress Quietly replace stata命令 replace female income

沙发
bobsport168 发表于 2012-5-8 15:17:41
for(i=0;i<17;i++)
{
    if educyr==i
         replace b0=.......
}
不知道你用的是什么语法
写道这里你应该有思路了吧
已有 1 人评分论坛币 信用等级 收起 理由
SpencerMeng + 20 + 1 观点有启发

总评分: 论坛币 + 20  信用等级 + 1   查看全部评分

藤椅
hqs00000 在职认证  发表于 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'
                        }
就是搞不出来,你的语句我是看明白了  不过怎么多次回归后并保存每次系数值,还是不太懂
失去的东西太多了!

板凳
bobsport168 发表于 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

地板
sungmoo 发表于 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

7
hustchen2012 在职认证  发表于 2014-4-25 08:31:33
松哥,一检索最先看到的就是你的高见,I am proud of you!

8
阿狸与桃子 发表于 2015-1-10 15:52:40
sungmoo 发表于 2012-5-8 18:44
statsby b0=_b[suppins], clear by(educyr): reg  ltotexp suppins phylim actlim totchr age female incom ...
您好,能请您有空的时候帮我解答一下这个帖子里的问题吗?打扰啦~
https://bbs.pinggu.org/forum.php? ... ;extra=#pid28225910

9
阿狸与桃子 发表于 2015-1-10 15:52:43
sungmoo 发表于 2012-5-8 18:44
statsby b0=_b[suppins], clear by(educyr): reg  ltotexp suppins phylim actlim totchr age female incom ...
您好,能请您有空的时候帮我解答一下这个帖子里的问题吗?打扰啦~
https://bbs.pinggu.org/forum.php? ... ;extra=#pid28225910

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

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