楼主: 桃子桃子酱
2622 10

[回归分析求助] 怎么保存无截距模型的分组回归系数为一新变量 [推广有奖]

  • 0关注
  • 0粉丝

已卖:530份资源

本科生

41%

还不是VIP/贵宾

-

威望
0
论坛币
5795 个
通用积分
3.9202
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
951 点
帖子
39
精华
0
在线时间
118 小时
注册时间
2017-9-9
最后登录
2024-4-8

楼主
桃子桃子酱 在职认证  学生认证  发表于 2018-9-17 15:44:35 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
现需要提取一面板数据分组回归的系数
比如
id  y        x
1  5.56  0.35
1  5.89  0.26
1  6.98  0.58
2  6.63  1.02
2  5.59  0.59
2  6.32  1.08

我用bcoeff y x,by(id) g(b)这个命令提取出来的系数还是有截距回归出来的系数。

求问各位大神要怎么才能提取这个分组的回归系数并生成一个新变量呀

二维码

扫码加我 拉你入群

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

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

关键词:回归系数 分组回归 无截距 面板数据 数据分组 stata

回帖推荐

黃河泉 发表于8楼  查看完整内容

请根据下列例子修改 (先 ssc install runby):

求学小灵通 发表于6楼  查看完整内容

set more off use "D:\file1.dta",clear matrix tbl = J(2, 2, 0) // collect results to a matrix matrix colnames tbl = id b // name the rows matrix rownames tbl = 1 2 // name the column of the matrix forv i=1/2{ qui reg y x if id==`i', noconstant matrix tbl[`i', 1] = `i' matrix tbl[`i', 2] = _b[x] } matrix list tbl // show t ...

沙发
求学小灵通 发表于 2018-9-17 16:19:34
matrix tbl = J(2, 1, 0) // collect results to a matrix
matrix colnames tbl = coefficent  // name the rows
matrix rownames tbl = 1 2  // name the column of the matrix
        forv i=1/2{
                qui reg y x if id==`i', noconstant
                matrix tbl[`i', 1] = _b[x]
        }
matrix list tbl // show the results

藤椅
求学小灵通 发表于 2018-9-17 16:21:38

matrix tbl = J(2, 1, 0) // collect results to a matrix
matrix colnames tbl = coefficent  // name the rows
matrix rownames tbl = 1 2  // name the column of the matrix
        forv i=1/2{
                qui reg y x if id==`i', noconstant
                matrix tbl[`i', 1] = _b[x]
        }
matrix list tbl // show the results
clear
svmat tbl, names(coeff) // use col names as variable names

板凳
麒零_之恋 在职认证  发表于 2018-9-17 18:06:08 来自手机
桃子桃子酱 发表于 2018-9-17 15:44
现需要提取一面板数据分组回归的系数
比如
id  y        x
明明是修正jones模型,感兴趣看我的帖子。。

报纸
桃子桃子酱 在职认证  学生认证  发表于 2018-9-18 10:12:19
求学小灵通 发表于 2018-9-17 16:21
matrix tbl = J(2, 1, 0) // collect results to a matrix
matrix colnames tbl = coefficent  // name  ...
谢谢大神,但我用这个代码跑出来不是我想要的结果。我想要的是在原来的数据里加入新生成的系数变量,这个要怎么弄呢

地板
求学小灵通 发表于 2018-9-18 10:26:05
桃子桃子酱 发表于 2018-9-18 10:12
谢谢大神,但我用这个代码跑出来不是我想要的结果。我想要的是在原来的数据里加入新生成的系数变量,这个 ...
set more off
use "D:\file1.dta",clear
matrix tbl = J(2, 2, 0) // collect results to a matrix
matrix colnames tbl = id b  // name the rows
matrix rownames tbl = 1 2  // name the column of the matrix
        forv i=1/2{
                qui reg y x if id==`i', noconstant
                matrix tbl[`i', 1] = `i'
                matrix tbl[`i', 2] = _b[x]
        }
matrix list tbl // show the results
clear
svmat tbl, names(b) // use col names as variable names
rename b1 id
rename b2 b
save "D:\file2.dta",replace

use "D:\file1.dta",clear
merge m:1 id using "D:\file2.dta"
drop _merge

7
求学小灵通 发表于 2018-9-18 10:26:41
桃子桃子酱 发表于 2018-9-18 10:12
谢谢大神,但我用这个代码跑出来不是我想要的结果。我想要的是在原来的数据里加入新生成的系数变量,这个 ...
把你文件名改为file1,放在D盘。

8
黃河泉 在职认证  发表于 2018-9-18 10:45:09
请根据下列例子修改 (先 ssc install runby):
  1. webuse grunfeld, clear
  2. capture program drop noconstant
  3. program define noconstant
  4.     reg invest mvalue kstock, nocons
  5.     gen est_mvalue = _b[mvalue]
  6.     gen est_kstock = _b[kstock]
  7. end
  8. runby noconstant, by(company)
复制代码

9
桃子桃子酱 在职认证  学生认证  发表于 2018-9-18 10:57:29
求学小灵通 发表于 2018-9-18 10:26
把你文件名改为file1,放在D盘。
好的,非常感谢,我现在的id是30个只用把J(2,2,0)改成J(30,2,0)就可以了是吗

10
桃子桃子酱 在职认证  学生认证  发表于 2018-9-18 11:08:36
黃河泉 发表于 2018-9-18 10:45
请根据下列例子修改 (先 ssc install runby):
可以啦,非常非常感谢!

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

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