1 Star 0 Fork 0

计量经济学/StataCommand

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

一些有用的Stata命令

Some useful Stata commands

1、基本命令

基本描述统计分析语法格式为:
sysuse "auto.dta", clear    //打开auto美国1978年汽车行业横截面数据

sum price mpg rep78 weight ,detail
pwcorr price mpg rep78 weight 
pwcorr price mpg rep78 weight ,sig star(0.05)

2、横截面分析

回归分析
use nerlove.dta,clear
reg lntc lnpf lnpk  lnpl 
reg lntc lnpf lnpk  lnpl ,noc
predict yhat                   //  拟合被解释变量GDP
predict e,residual              //  计算残差
rvfplot  
参数检验
regress lntc lnpk  lnpl
test lnpk=0.5                      //检验系数
test lnpk=lnpl
estat hettest                     //异方差BP检验
estat imtest,white                //异方差white检验
estat vif                         //多重共线性检验
带约束条件检验
cons  1 lnpk+lnpl=1
cons  2 lnpk+lnpl=1.6
cnsreg lntc lnpk  lnpl,constraints(1)  //有约束的回归
cnsreg lntc lnpk  lnpl,constraints(2)  //有约束的回归
bootstrap, reps(200):regress lntc lnpk  lnpl //bootstrap 方法的回归
bootstrap _b :regress lntc lnpk  lnpl      //bootstrap 方法的回归
稳健回归
regress lntc lnpk  lnpl
estimates  store model1
reg lntc lnpk  lnpl,robust
estimates store model2
esttab model*  using huigui.rtf,r2 ar2 nogap replace

3、 时间序列模型

时间序列声明
use 时间序列数据.dta, clear
tsset year   //时间序列声明
单位根检验
use 时间序列数据.dta, clear
dfuller d.m,lag(2)                //ADF检验
dfuller m,nocon regress           //ADF检验
dfuller m,trend regress
pperron m,lag(2)                  //PP检验                   
pperron m,nocon regress           
pperron d.m,regress
dfgls m                          //DF-GLS检验
kpss  m,notrend                   //KPSS检验
ECM单位根检验
reg m s g 
estimates  store model1
predict ecm,residual
reg d.m d.s d.g ecm   //ECM模型
VAR模型
varsoc m s g ,maxlag(5)
var m s g ,lags(1/4)
varstable,graph
vargranger
irf create myrif,set(myrif) replace
irf graph irf
VECM模型
vecrank m s g,lags(4)
varsoc m s g,maxlag(5)
vec m s g,lags(4) 
reg m s g 
vecstable,graph

4、 面板模型

面板声明
use FDI.dtar, clear
xtset id year
xtdes
xtline lngdp
单位根检验
xtunitroot llc lngdp,lags(2) trend
xtunitroot llc d.lngdp,lags(2) trend
xtunitroot ips lngdp
xtunitroot ips d.lngdp
协整检验
xtwest lngdp lnfdi lni,lags(2)
混合回归
reg lngdp lnfdi lnie
reg lngdp lnfdi lnie,robust
reg lngdp lnfdi lnie,vce(cluster id)
固定效应
xtreg lngdp lnfdi lnie lnex lnim  lnci lngp,fe
xtreg lngdp lnfdi lnie lnex lnim  lnci lngp,fe,fe vce (cluster id)
xi:xtreg lngdp lnfdi lnie lnex lnim  lnci lngp  i.id,vce(cluster id) //LSDV 考虑个体固定效应
tab year,gen(year)
xtreg lngdp lnfdi lnie lnex lnim  lnci lngp year2-year14,fe 
xtreg lngdp lnfdi lnie lnex lnim  lnci lngp year2-year14,fe vce (cluster id)
test year2=year3=year4=year5=0
随机效应
xtreg lngdp lnfdi lnie lnex lnim  lnci lngp,re mle
xtreg lngdp lnfdi lnie lnex lnim  lnci lngp,vce (cluster id) 
xtreg lngdp lnfdi lnie lnex lnim  lnci lngp,re mle    //随机效应的MLE参数估计方法
Hausman检验--随机和固定效应的检验
xtreg lngdp lnfdi lnie lnex lnim  lnci lngp,re
est store re
xtreg lngdp lnfdi lnie lnex lnim  lnci lngp,fe
est store fe
hausman fe re
est table re fe, b(%6.3f) star(0.1 0.05 0.01) 
outreg2 [fe re] using daqinxueshu.doc,stats(coef,tstat) addstat(Ajusted R2,`e(r2_a)') replace

5、Some useful Stata commands

help : online help on a specific command

findit : online references on a keyword or topic

ssc : access routines from the SSC Archive

pwd : print the working directory

cd : change the working directory

log : log output to an external file

tsset : define the time indicator for timeseries or panel data

compress : economize on space used by variables

clear : clear memory

quietly : do not show the results of a command

update query : see if Stata is up to date

adoupdate : see if user-written commands are up to date

exit : exit the program (,clear if dataset is not saved)

Data manipulation commands

generate : create a new variable

describe : describe a data set or current contents of memory

replace : modify an existing variable

rename : rename variable

renvars : rename a set of variables

sort : change the sort order of the dataset

drop : drop certain variables and/or observations

keep : keep only certain variables and/or observations

append : combine datasets by stacking

merge : merge datasets (one-to-one or match merge)

encode : generate numeric variable from categorical variable

recode : recode categorical variable

destring : convert string variables to numeric

foreach : loop over elements of a list, performing a block of code

forvalues : loop over a numlist, performing a block of code

local : define or modify a local macro (scalar variable)



use : load a Stata data set

save : write the contents of memory to a Stata data set

insheet : load a text file in tab- or comma-delimited format

infile : load a text file in space-delimited format or as defined in a

dictionary

outfile : write a text file in space- or comma-delimited format

outsheet : write a text file in tab- or comma-delimited format

contract : make a dataset of frequencies

collapse : make a dataset of summary statistics

tab : abbreviation for tabulate: 1- and 2-way tables

table : tables of summary statistics

Statistical commands


summarize : descriptive statistics

correlate : correlation matrices

ttest : perform 1-, 2-sample and paired t-tests

anova : 1-, 2-, n-way analysis of variance

regress : least squares regression

predict : generate fitted values, residuals, etc.

test : test linear hypotheses on parameters

lincom : linear combinations of parameters

cnsreg : regression with linear constraints

testnl : test nonlinear hypothesis on parameters

margins : marginal effects (elasticities, etc.)

ivregress : instrumental variables regression

prais : regression with AR(1) errors

sureg : seemingly unrelated regressions

reg3 : three-stage least squares

qreg : quantile regression

Limited dependent variable estimation commands

logit, logistic : logit model, logistic regression

probit : binomial probit model

tobit : one- and two-limit Tobit model

cnsreg : Censored normal regression (generalized Tobit)

ologit, oprobit : ordered logit and probit models

mlogit : multinomial logit model

poisson : Poisson regression

heckman : selection model

Time series estimation commands

arima : Box–Jenkins models, regressions with ARMA errors

arfima : Box–Jenkins models with long memory errors

arch : models of autoregressive conditional heteroskedasticity

dfgls : unit root tests

corrgram : correlogram estimation

var : vector autoregressions (basic and structural)

irf : impulse response functions, variance decompositions

vec : vector error–correction models (cointegration)

sspace : state-space models

dfactor : dynamic factor models

ucm : unobserved-components models

rolling: prefix permitting rolling or recursive estimation over subsets

Panel data estimation commands


xtreg,fe : fixed effects estimator

xtreg,re : random effects estimator

xtgls : panel-data models using generalized least squares

xtivreg : instrumental variables panel data estimator

xtlogit : panel-data logit models

xtprobit : panel-data probit models

xtpois : panel-data Poisson regression

xtgee : panel-data models using generalized estimating equations

xtmixed : linear mixed (multi-level) models

xtabond : Arellano-Bond dynamic panel data estimator

空文件

简介

一些有用的Stata命令 展开 收起
取消

发行版

暂无发行版

贡献者 (1)

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/econometric/stata-command.git
git@gitee.com:econometric/stata-command.git
econometric
stata-command
StataCommand
master

搜索帮助