计量经济学实验STATA:stata基本知识:1、基本操作 :(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(7)考察变量的统计特征: summarize x1 su x1 if q>=10000 su q,detail su tabulate x1 correlate x1 x2 x3 x4 x5 x6 (8)画图 : histogram x1, width(1000) frequency kdensity x1 scatter x1 x2 twoway (scatter x1 x2) (lfit x1 x2) twoway (scatter x1 x2) (qfit x1 x2) (9)生成新变量: gen lnx1=log(x1) gen q2=q^2 gen lnx1lnx2=lnx1*lnx2 gen larg=(x1>=10000) rename larg largedrop large g large=(q>=6000) replace large=(q>=6000) drop ln*(10)计算功能: display log(2)(11)线性回归分析: 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(12)约束回归 : 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)(13)stata的日志 : File-log-begin-输入文件名 log off 暂时关闭 log on 恢复使用 log close 彻底退出(14)stata命令库更新 :Update all help command