全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
2512 10
2018-09-17
现需要提取一面板数据分组回归的系数
比如
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)这个命令提取出来的系数还是有截距回归出来的系数。

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

二维码

扫码加我 拉你入群

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

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

全部回复
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
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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