代码拉取完成,页面将自动刷新
Some useful Stata commands
基本描述统计分析语法格式为:
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)
回归分析
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
时间序列声明
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
面板声明
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
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)
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
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
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
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
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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。