stata命令汇总_⼀⽂读懂stata模型汇总⼊门命令及108个常⽤
命令
推荐阅读: Stata寒假研讨班_2020年1⽉_第13&14届“⾼级计量经济学及stata应⽤”研讨班@上海/北京专场_ ⽕热报名中 ⼀分钟看完
stata模型汇总⼊门命令 1 基本命令 基本描述统计分析语法格式为:
sysuse "auto.dta", clear    //打开auto美国1978年汽车⾏业横截⾯数据sum price mpg rep78 weight ,detailpwcorr price mpg rep78 weight pwcorr price mpg rep78 we
2 横截⾯分析 回归分析
use nerlove.dta,clearreg lntc lnpf lnpk  lnpl reg lntc lnpf lnpk  lnpl ,nocpredict yhat                  //  拟合被解释变量GDPpredict e,residual              //  计算残差rvfplot
参数检验
regress lntc lnpk  lnpltest lnpk=0.5                      //检验系数test lnpk=lnplestat hettest                    //异⽅差BP检验estat imtest,white                //异⽅差white检验esta
带约束条件检验
cons  1 lnpk+lnpl=1cons  2 lnpk+lnpl=1.6cnsreg lntc lnpk  lnpl,constraints(1)  //有约束的回归cnsreg lntc lnpk  lnpl,constraints(2)  //有约束的回归bootstrap, reps(200
稳健回归
regress lntc lnpk  lnplestimates  store model1reg lntc lnpk  lnpl,robustestimates store model2esttab model*  f,r2 ar2 nogap replace
3 时间序列模型 时间序列声明
use 时间序列数据.dta, cleartsset year  //时间序列声明
单位根检验
use 时间序列数据.dta, cleardfuller d.m,lag(2)                //ADF检验dfuller m,nocon regress          //ADF检验dfuller m,trend regresspperron m,lag(2)                  //PP
ECM单位根检验
reg m s g estimates  store model1predict ecm,residualreg d.m d.s d.g ecm  //ECM模型
VAR模型
varsoc m s g ,maxlag(5)var m s g ,lags(1/4)varstable,graphvargrangerirf create myrif,set(myrif) replaceirf 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, clearxtset id yearxtdesxtline lngdp
单位根检验
xtunitroot llc lngdp,lags(2) trendxtunitroot llc d.lngdp,lags(2) trendxtunitroot ips lngdpxtunitroot ips d.lngdp
协整检验
xtwest lngdp lnfdi lni,lags(2)
混合回归
reg lngdp lnfdi lniereg lngdp lnfdi lnie,robustreg lngdp lnfdi lnie,vce(cluster id)
固定效应
xtreg lngdp lnfdi lnie lnex lnim  lnci lngp,fextreg lngdp lnfdi lnie lnex lnim  lnci lngp,fe,fe vce (cluster id)xi:xtreg lngdp lnfdi lnie lnex lnim  lnci lngp  i.id,vce(clu
随机效应
xtreg lngdp lnfdi lnie lnex lnim  lnci lngp,re mlextreg lngdp lnfdi lnie lnex lnim  lnci lngp,vce (cluster id) xtreg lngdp lnfdi lnie lnex lnim  lnci lngp,re mle    //随机效应的
Hausman检验--随机和固定效应的检验
xtreg lngdp lnfdi lnie lnex lnim  lnci lngp,reest store rextreg lngdp lnfdi lnie lnex lnim  lnci lngp,feest store fehausman fe reest table re fe, b(%6.3f) star(0.1 0
⼀⽂读懂108个常⽤stata命令
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