计量经济学stata操作指南

计量经济学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
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
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
*下载非官方软件
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.
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
2010年广东高考数学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 p price income
estat bgodfrey
estat dwatson

本文发布于:2024-09-20 15:21:14,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/614669.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:数据   变量   使用   检验   估计
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议