文档详情

计量经济学stata操作指南.pdf

小**
实名认证
店铺
PDF
137.78KB
约16页
文档ID:89753617
计量经济学stata操作指南.pdf_第1页
1/16

Stata 操作指南 吉首大学商学院内部资料 丁建军 1 计量经济学计量经济学 stata 操作操作((实验课实验课)) 第一章第一章 stata 基本知识基本知识 1、stata 窗口介绍 2、基本操作 (1)窗口锁定:Edit-preferences-general preferences-windowing-lock splitter (2)数据导入 (3)打开文件:use E:\example.dta,clear (4)日期数据导入: gen newvar=date(varname, “ymd”) format newvar %td 年度数据 gen newvar=monthly(varname, “ym”) format newvar %tm 月度数据 gen newvar=quarterly(varname, “yq”) format newvar %tq 季度数据 (5)变量标签 Label variable tc ` “total output” ’ (6)审视数据 describe list x1 x2 list x1 x2 in 1/5 list x1 x2 if q=1000 drop if q=1000 keep if q=1000 (6)考察变量的统计特征 summarize x1 su x1 if q=10000 su q,detail su tabulate x1 correlate x1 x2 x3 x4 x5 x6 (7)画图 histogram x1, width(1000) frequency kdensity x1 scatter x1 x2 twoway (scatter x1 x2) (lfit x1 x2) twoway (scatter x1 x2) (qfit x1 x2) (8)生成新变量 gen lnx1=log(x1) gen q2=q^2 gen lnx1lnx2=lnx1*lnx2 gen larg=(x1=10000) rename larg large Stata 操作指南 吉首大学商学院内部资料 丁建军 2 drop large g large=(q=6000) replace large=(q=6000) drop ln* (8)计算功能 display log(2) (9)线性回归分析 regress y1 x1 x2 x3 x4 vce #显示估计系数的协方差矩阵 reg y1 x1 x2 x3 x4,noc #不要常数项 reg y1 x1 x2 x3 x4 if q=6000 reg y1 x1 x2 x3 x4 if large reg y1 x1 x2 x3 x4 if large==0 reg y1 x1 x2 x3 x4 if ~large predict yhat predict e1,residual display 1/_b[x1] test x1=1 # F 检验,变量 x1 的系数等于 1 test (x1=1) (x2+x3+x4=1) # F 联合假设检验 test x1 x2 #系数显著性的联合检验 testnl _b[x1]= _b[x2]^2 (10)约束回归 constraint def 1 x1+x2+x3=1 cnsreg y1 x1 x2 x3 x4,c(1) cons def 2 x4=1 cnsreg y1 x1 x2 x3 x4,c(1-2) (11)stata 的日志 File-log-begin-输入文件名 log off 暂时关闭 log on 恢复使用 log close 彻底退出 (12)stata 命令库更新 Update all help command 第二章第二章 有关大样本有关大样本 ols 的的 stata 命令命令及实例及实例 (1)ols 估计的稳健标准差 reg y x1 x2 x3,robust (2)实例 use example.dta,clear reg y1 x1 x2 x3 x4 test x1=1 reg y1 x1 x2 x3 x4,r Stata 操作指南 吉首大学商学院内部资料 丁建军 3 test x1=1 testnl _b[x1]=_b[x2]^2 第三章第三章 最大似然估计法的最大似然估计法的 stata 命令及实例命令及实例 (1)最大似然估计 help ml (2)LR 检验 lrtest #对面板数据中的异方差进行检验 (3)正态分布检验 sysuse auto #调用系统数据集 auto.dta hist mpg,normal kdensity mpg,normal qnorm mpg *手工计算 JB 统计量 sum mpg,detail di (r(N)/6)*((r(skewness)^2)+[(1/4)*(r(kurtosis)-3)^2]) di chi2tail(自由度,上一步计算值) *下载非官方程序 ssc install jb6 jb6 mpg *正态分布的三个检验 sktest mpg swilk mpg sfrancia mpg *取对数后再检验 gen lnmpg=log(mpg) kdensity lnmpg, normal jb6 lnmpg sktest lnmpg 第第四四章章 处理异方差的处理异方差的 stata 命令及实例命令及实例 (1)画残差图 rvfplot rvfplot varname *例题 use example.dta,clear reg y x1 x2 x3 x4 rvfplot # 与拟合值的散点图 rvfplot x1 # 画残差与解释变量的散点图 (2)怀特检验 estat imtest,white *下载非官方软件 Stata 操作指南 吉首大学商学院内部资料 丁建军 4 ssc install whitetst (3)BP 检验 estat hettest #默认设置为使用拟合值 estat hettest,rhs #使用方程右边的解释变量 estat hettest [varlist] #指定使用某些解释变量 estat hettest,iid estat hettest,rhs iid estat hettest [varlist],iid (4)WLS reg y x1 x2 x3 x4 [aw=1/var] *例题 quietly reg y x1 x2 x3 x4 predict e1,res gen e2=e1^2 gen lne2=log(e2) reg lne2 x2,noc predict lne2f gen e2f=exp(lne2f) reg y x1 x2 x3 x4 [aw=1/e2f] (5)stata 命令的批处理(写程序) Window-do-file editor-new do-file #WLS for example log using E:\wls_example.smcl,replace set more off use E:\example.dta,clear reg y x1 x2 x3 x4 predict e1,res gen e2=e1^2 g lne2=log(e2) reg lne2 x2,noc predict lne2f g e2f=exp(lne2f) *wls regression reg y x1 x2 x3 x4 [aw=1/e2f] log close exit 第五章第五章 处理自相关的处理自相关的 stata 命令及实例命令及实例 (1)滞后算子/差分算子 tsset year l. l2. D. D2. Stata 操作指南 吉首大学商学院内部资料 丁建军 5 LD. (2)画残差图 scatter e1 l.e1 ac e1 pac e1 (3)BG 检验 estat bgodfrey(默认 p=1) estat bgodfrey,lags(p) estat bgodfrey,nomiss0(使用不添加 0 的 BG 检验) (4)Ljung-Box Q 检验 reg y x1 x2 x3 x4 predict e1,resid wntestq e1 wntestq e1,lags(p) * wntestq 指的是“white noise test Q” ,因为白噪声没有自相关 (5)DW 检验 做完 OLS 回归后,使用 estat dwatson (6)HAC 稳健标准差 newey y x1 x2 x3 x4,lag(p) reg y x1 x2 x3 x4,cluster(varname) (7)处理一阶自相关的 FGLS prais y x1 x2 x3 x4 (使用默认的 PW 估计方法) prais y x1 x2 x3 x4,corc (使用 CO 估计法) (8)实例 use icecream.dta, clear tsset time graph twoway connect consumption temp100 time, msymbol(circle) msymbol(triangle) reg consumption temp price income predict e1, res g e2=l.e1 twoway (scatter e1 e2) (lfit e1 e2) ac e1 pac e1 estat bgodfrey wntestq e1 estat dwatson newey consumption temp price income, lag (3) prais consumption temp price income, corc prais consumption temp price income, nolog reg consumption temp l.temp price income estat bgodfrey estat dwatson Stata 操作指南 吉首大学商学院内部资料 丁建军 6 第六章第六章 模型设定模型设定与数据问题与数据问题 (1)解释变量的选择 reg y x1 x2 x3 estat ic *例题 use icecream.dta, clear reg consumption temp price income estat ic reg consumption temp l.temp price income estat ic (2)对函数形式的检验(reset 检验) reg y x1 x2 x3 estat ovtest (使用被解释变量的 2、3、4 次方作为非线性项) estat ovtest, rhs (使用解释变量的幂作为非线性项,ovtest-omitted variable test) *例题 use nerlove.dta, clear reg lntc lnq lnpl lnpk lnpf estat ovtest g lnq2=lnq^2 reg lntc lnq lnq2 lnpl lnpk lnpf estat ovtest (3)多重共线性 estat vif *例题 use nerlove.dta, clear reg lntc lnq lnpl lnpk lnpf estat vif (4)极端数据 reg y x1 x2 x3 predict lev, leverage (列出所有解释变量的 lev 值) gsort –lev sum lev list lev in 1/3 *例题 use nerlove.dta, clear quietly reg lntc lnq lnpl lnpk lnpf predict lev, leverage sum lev gsort –lev list lev in 1。

下载提示
相似文档
正为您匹配相似的精品文档