加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

Lesson-5

(2021-03-02 19:23:47)
*construct virtual data with cycling grammar and conduct nbreg/poisson model regression.
clear
forv i=1/10{
forv j=2010/2020{
set obs 1
generate stkid=`i'
generate year=`j'
generate indcd=`i'+100
generate y=round(10*runiform())
generate x=runiform()
generate x1=runiform()
generate x2=runiform()
generate x3=runiform()
generate x4=runiform()
generate x5=runiform()
save data`i'`j'.dta,replace
clear
}
}
use data12010.dta,clear
forv j=2011/2020{
append using data1`j'.dta
}

forv i=2/10{
forv j=2010/2020{
append using data`i'`j'.dta
}
}
save datatest.dta,replace
forv i=1/10{
forv j=2010/2020{
erase data`i'`j'.dta
}
}
use datatest.dta,clear
br
replace y=1 if y==0
global Model "nbreg"
global DV "y"
global IV "x"
global Moderator "x1"
global Control "x3-x5"
center $IV $Moderator
$Model $DV $IV $Control
est store a1
$Model $DV $Moderator $Control
est store a2
$Model $DV $IV $Moderator $Control
est store a3
$Model $DV c.c_$IV##c.c_$Moderator $Control
est store a4
outreg2 [a*] using regression,excel dec(3) replace alpha(0.01,0.05,0.1)
logout,save(summary) excel dec(3) replace:summarize $DV $IV $Moderator $Control
logout,save(cor) excel dec(3) replace:pwcorr_a $DV $IV $Moderator $Control

*we can use another form of dependent variable which is logarithm of dv 
*stating from the end of the first sentence, under the logarithm precondition,we can use OLS model
gen lny=ln(y)
reg lny c.c_$IV##c.c_$Moderator $Control

*if we suspect independent variable is endogenous we can solve it in two ways at least
*one is use one year lagged variables to fit endogenous variable to form an exogenous variable
*another is to use averaged industry variable excluding itself.
*solve endogeneity issue with one-year lagged variable
tsset stkid year
gen lx1=l.x1
gen lx2=l.x2
gen lx3=l.x3
gen lx4=l.x4
gen lx5=l.x5
reg x lx1-lx5
predict xr1
center xr1
$Model $DV c.c_xr1##c.c_$Moderator $Control

*solve endogenous issue with average industry variable except itself.
*first of all i have to create some industries same
replace indcd=101 if indcd==110
replace indcd=102 if indcd==109
replace indcd=103 if indcd==108
replace indcd=104 if indcd==107
replace indcd=105 if indcd==106
gen n=1
bysort indcd year:egen sumx=sum(x)
bysort indcd year:egen sumn=sum(n)
gen aveindx=(sumx-x)/(sumn-1)
reg x aveindx x1-x5
predict xr2
center xr2
$Model $DV c.c_xr2##c.c_$Moderator $Control

*we can also use poisson to replace nbreg though it differs a little from nbreg
poisson $DV c.c_$IV##c.c_$Moderator $Control

*if data is panel form we can use xtnbreg or xtpoisson to conduct regression
xtset stkid year
eststo:xtnbreg $DV c.c_$IV##c.c_$Moderator $Control
eststo:xtpoisson lny c.c_$IV##c.c_$Moderator $Control
esttab,t(%4.3f) b(%4.2f)
eststo clear



0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有