Stata面板设置与面板数据多元线性回归与泊松回归命令
1. 设置面板
[XT] xtset – Declare data to be panel data
xtset panelvar timevar [, tsoptions]
# example
xtset business_id year
常用面板数据命令 (具体用法用help查一下)
xtset: Declare a dataset to be panel data
xtdescribe: Describe pattern of xt data
xtsum: Summarize xt data
xttab: Tabulate xt data
xtdata: Faster specification searches with xt data
xtline: Line plots with xt data
xtreg: Fixed-, between- and random-effects, and population-averaged linear models
xtregar: Fixed- and random-effects linear models with an AR(1) disturbance
xtmixed: Multilevel mixed-effects linear regression
xtgls: Panel-data models using GLS
xtpcse: OLS or Prais-Winsten models with panel-corrected standard errors
xthtaylor; Hausman-Taylor estimator for error-components models
xtfrontier: Stochastic frontier models for panel data
xtrc: Random coefficients models
xtivreg: Instrumental variables and two-stage least squares for panel-data models
xtunitroot: Panel-data unit-root tests
xtabond: Arellano-Bond linear dynamic panel-data estimator xtdpdsys Arellano-Bond/Blundell-Bond estimation
xtdpd: Linear dynamic panel-data estimation
xttobit: Random-effects tobit models
xtintreg: Random-effects interval-data regression models
xtlogit: Fixed-effects, random-effects, & population-averaged logit models
xtprobit: Random-effects and population-averaged probit models
xtcloglog: Random-effects and population-averaged cloglog models
xtpoisson: Fixed-effects, random-effects, & population-averaged Poisson models
xtnbreg: Fixed-effects, random-effects, & population-averaged negative binomial models
xtmelogit: Multilevel mixed-effects logistic regression
xtmepoisson: Multilevel mixed-effects Poisson regression
xtgee: Population-averaged panel-data models using GEE
参考来源:Stata:面板数据计量方法汇总
面板设置常见问题
1.1 pannel variable为string类型
把 string 转换为数字类型
# 自己改一下pannel variable
encode business_id, gen(business_id_1)
drop business_id
rename business_id_1 business_id
1.2 时间变量为string类型
- 如果是只有年份的数据,可以直接把字符串转换为数值类型
destring year, replace force
- 如果时间变量还包含日期,则需要多一步转换
我的日期数据是这样的,包括了时分秒
# 把时间转换成双精度数值类型
gen double time = clock(date, "YMDhms")
转换后就会成为一串数值
stata常用时间命令,根据自己时间数据的格式以及需求选择合适的来用
Clock(s1,s2[,Y])
clock(s1,s2[,Y])
date(s1,s2[,Y])
daily(s1,s2[,Y])
具体还可以参考:
STATA日期函数汇总
【STATA】时间变量处理,字符串转为日期时间
1.3 报错:repeated time values within panel
面板数据下同一vari不允许出现同样的时间,因此我们需要把重复的数据去除
# 报告重复数据
duplicates report business_id time
# 列出重复数据
duplicates list business_id time
# 去除重复数据
duplicates drop business_id time, force
2. 面板数据多元线性回归
[XT] xtreg – Fixed-, between-, and random-effects and population-averaged linear models
GLS random-effects (RE) modelxtreg depvar [indepvars] [if] [in] [, re RE_options]Between-effects (BE) modelxtreg depvar [indepvars] [if] [in] , be [BE_options]Fixed-effects (FE) modelxtreg depvar [indepvars] [if] [in] [weight] , fe [FE_options]ML random-effects (MLE) modelxtreg depvar [indepvars] [if] [in] [weight] , mle [MLE_options]Population-averaged (PA) modelxtreg depvar [indepvars] [if] [in] [weight] , pa [PA_options]
# 一维聚类调整异方差-序列相关稳健型标准误 (HAC)
xtreg like stars text_len sentiment polarity i.year, fe vce(cluster business_id)
# 二维聚类 SE
webuse "nlswork.dta", clear
vce2way regress ln_wage age grade, cluster(idcode year)
参考来源:Stata 连享会: 聚类调整标准误笔记
3. 面板数据泊松回归
[XT] xtpoisson – Fixed-effects, random-effects, and population-averaged Poisson models
Random-effects (RE) modelxtpoisson depvar [indepvars] [if] [in] [weight] [, re RE_options]Conditional fixed-effects (FE) modelxtpoisson depvar [indepvars] [if] [in] [weight] , fe [FE_options]Population-averaged (PA) modelxtpoisson depvar [indepvars] [if] [in] [weight] , pa [PA_options]
- example
# 一维聚类调整异方差-序列相关稳健型标准误 (HAC)
xtpoisson like stars text_len sentiment polarity i.year, vce(robust) i(business_id) fe
在这里回归模型会去掉 “one obs per group” 或 “all zero outcomes”的数据, 当DV不同IV相同时去掉的数据量也不一样。为了保证多个DV的模型都使用相同的数据进行回归分析,我们可以把每个DV下xtpoisson回归所使用的数据都标上记号
# xtpoisson useful stars text_len sentiment polarity i.year, vce(robust) i(business_id) fe
gen sample_useful=e(sample)
# xtpoisson funny stars text_len sentiment polarity i.year, vce(robust) i(business_id) fe
gen sample_funny=e(sample)
# xtpoisson cool stars text_len sentiment polarity i.year, vce(robust) i(business_id) fe
gen sample_cool=e(sample)
然后再进行回归分析
xtpoisson useful stars text_len sentiment polarity i.year if sample_useful==1 & sample_funny==1 & sample_cool==1, vce(robust) i(business_id) fextpoisson funny stars text_len sentiment polarity i.year if sample_useful==1 & sample_funny==1 & sample_cool==1, vce(robust) i(business_id) fextpoisson cool stars text_len sentiment polarity i.year if sample_useful==1 & sample_funny==1 & sample_cool==1, vce(robust) i(business_id) fe
Stata面板设置与面板数据多元线性回归与泊松回归命令相关推荐
- Stata的多元线性回归与泊松回归
1. 相关性检测 Pearson相关系数 correlate [varlist] [if] [in] [weight] [, correlate_options] Spearman相关系数 pwcor ...
- Python+statsmodels实现多元线性回归和泊松回归
statsmodels是python中专门用于统计学分析的包,它能够帮我们在模型未知的情况下来检验模型的线性显著性 更多回归模型见:statsmodels-formula-api 在建立回归方程前首先 ...
- 19 多元线性回归与模型回归
19 多元线性回归与模型回归 标签:机器学习与数据挖掘 1.调整 R 2 R^2 R2 对于 R 2 R^2 R2,只要添加入新的参数,它就会变大,不过这个变量有没有用.而我们采用 调 整 R 2 ...
- 总离差平方和公式_在多元线性回归模型中,回归平方和与总离差平方和的比值称为( )_学小易找答案...
[单选题]参数 的估计量 具备有效性是指( ) [多选题]关于多重判定系数 的公式正确的有( ) [多选题]不满足OLS基本假定的情况,主要包括( ) [单选题]在多元回归分析中,F检验是用来检验( ...
- 【计量经济学及Stata应用】第 5 章 多元线性回归
目录 5.1 二元线性回归 5.2 多元线性回归模型 5.3 OLS估计量的推导 5.4 OLS的几何解释 5.5 拟合优度 5.6 古典线性回归模型的假定 5.7 OLS的小样本性质 5.8 对单个 ...
- 多元线性回归,岭回归,lasso回归(具体代码(包括调用库代码和手写代码实现)+一点点心得)
最近数据挖掘导论老师布置了一项作业,主要就是线性回归的实现,笔者之前听过吴恩达的线性回归的网课,但一直没有进行代码的实现,这次正好相对系统的整理一下,方便各位同学的学习,也希望能够对其进行优化,优化的 ...
- 机器学习(多元线性回归模型逻辑回归)
多元线性回归 定义:回归分析中,含有两个或者两个以上自变量,称为多元回归,若自变量系数为1,则此回归为多元线性回归. (特殊的:自变量个数为1个,为一元线性回归)多元线性回归模型如下所示: 如上图所示 ...
- 多元线性回归哑变量设置方法
多元线性回归是研究一个连续型变量和其他多个变量间线性关系的统计学分析方法,如果在自变量中存在分类变量,如果直接将分类变量和连续性变量统一纳入模型进行分析是有问题的,尤其是无序分类资料,即使进入了模型, ...
- Python 实战多元线性回归模型,附带原理+代码
作者 | 萝卜 来源 | 早起Python( ID:zaoqi-python ) 「多元线性回归模型」非常常见,是大多数人入门机器学习的第一个案例,尽管如此,里面还是有许多值得学习和注意的地方.其中多 ...
最新文章
- 安装MySQL出现的this application
- 华为海思HISILICON
- CSS实现TikTok文字抖动效果
- ExtJS Panel主要配置列表
- 前端清单之Vue.js篇
- htmL全栈开发项目实例,【译】基于MEAN的全栈开发实例教程6(完)
- 元胞自动机简介(美赛复习一)
- html 保存 文字变乱码怎么办,html文字为什么会乱码
- telnet 回显 linux,telnet实现本地回显
- excel常用函数大全及示例(一)
- 什么是增量绩效管理?华为是如何做
- html中超链接使用_html超链接有哪些类型 html中,超链接用的是什么标签
- 什么是Photoshop中的图层和蒙版?
- python中大于多少小于怎么表示_Python While语句大于/小于符号
- 30条html代码编写规范
- Simulink代码生成: 使能子系统及其代码
- 游戏服务器引擎的设计(一)介绍游戏服务器部署框架
- 职场新人应该如何培养项目管理的能力?
- (论文阅读笔记)OLE:正交低秩嵌入,即插即用的几何损失
- 通过HttpURLConnection连接上传文件和参数