xtgls 截面-时序混合模型,可处理异方差、组内序列相关和组间相关性 xtpcse OLS or Prais-Winsten models with panel-corrected standard errors xtrchh Hildreth-Houck random coefficients models xtivreg 面板模型的工具变量或两阶段最小二乘法估计 xtabond Arellano-Bond(1991)线性动态面板数据模型估计
xtintreg Random-effects interval data regression models xtlogit Fe, Re, Pa logit models xtprobit Re, Pa probit models xtcloglog Re, Pa cloglog models xtpoisson Fe, Re, Pa Poisson models xtnbreg Fe, Re, Pa negative binomial models xtfrontier 面板随机前沿模型
xthtylor Hausman-Taylor estimator for error-components models
predictnl 获得非线性估计的拟合值、残差等 test 线性约束的假设检验,Wald 检验 testnl 非线性约束的假设检验
vce 列示参数估计值的方差-协方差矩阵
表2-6: 二维图种类一览
图形种类简单描述 scatter scatterplot line line plot connected connected-line plot scatteri scatter with immediate arguments area line plot with shading bar bar plot spike spike plot dropline dropline plot dot dot plot rarea range plot with area shading rbar range plot with bars rspike range plot with spikes rcap range plot with capped spikes rcapsym range plot with spikes capped with symbols rscatter range plot with markers rline range plot with lines rconnected range plot with lines and markers tsline time-series plot tsrline time-series range plot mband median-band line plot mspline spline line plot lowess LOWESS line plot lfit linear prediction plot qfit quadratic prediction plot fpfit fractional polynomial plot lfitci linear prediction plot with CIs qfitci quadratic prediction plot with CIs fpfitci fractional polynomial plot with CIs function line plot of function histogram histogram plot kdensity kernel density plot 表2-7: 二维图选项一览
选项类别简单描述
added line options draw lines at specified y or x values added text option display text at specified(y,x)value axis options labels, ticks, grids, log scales title options titles, subtitles, notes, captions legend option legend explaining what means what scale(#)resize text, markers, and line widths region options outlining, shading, aspect ratio, size aspect option constrain aspect ratio of plot region scheme(schemename)overall look by(varlist,...)repeat for subgroups nodraw suppress display of graph name(name,...)specify name for graph saving(filename,...)save graph in file advanced options difficult to explain 表2-9: 模拟分析相关命令一览
_all _n _N _skip _b _coef _cons _pi _pred _rc _weight double float long int in if using with 命令:
读入数据一种方式 input x y 1 4 2 5.5 3 6.2 4 7.7 5 8.5 end su/summarise/sum x 或 su/summarise/sum x,d 对分组的描述: sort group by group:su x %%%%% tabstat economy,stats(max)%返回变量economy的最大值
_N 数据库中观察值的总个数。_n 当前观察值的位置。_pi 圆周率π的数值。list gen/generate %产生数列 egen wagemax=max(wage)clear use by(分组变量)set more 1/0 count %计数
gsort +x(升序)gsort-x(降序)sort x 升序;并且其它变量顺序会跟着改变 label var y “消费” %添加标签 describe %描述数据文件的整体,包括观测总数,变量总数,生成日期,每个变量的存储类型(storage type),标签(label)replace x5=2*y if x!=3 %替换变量值
replace age = 25 in 107 %令第107个观测中age为25 rename y2 u %改变变量名
drop in 2 %删除全部变量的第2行
drop if x==.删去x为缺失值的所有记录
keep if x<2 %保留小于2的数据,其余变量跟随x改变 keep in 2/10 %保留第2-10个数
keep x1-x5 %保留数据库中介于x1和x5间的所有变量(包括x1和x5),其余变量删除
ci x1 x2,by(group)%算出置信区间,不过先前对group要先排序,即sort group;
cii 10 2 %obs=10,mean=2,以二项分布形式,计算置信区间 centile x,centile(2.5 25 50 75 97.5)%取分位数 correlate/corr x y z %相关系数
pwcorr x y,sig %给出原假设r=0的命令 %如果变量非服从正态分布,则spearman x y regress/reg mean year %回归方程建立 reg y x,noconstant %无常数项 predict meanhat %预测拟合值 predict e,residual %得到残差 estat hettest % 异方差检验
dwstat % Durbin-Watson自相关检验 vif % 方差膨胀因子
logit y x1 x2 x3(y取0或1,是被解释变量,x1-x3是被解释变量)%logit回归
probit y x1 x2 x3(y取0或1,是被解释变量,x1-x3是被解释变量)%probit回归
tobit y x1 x2 x3(y取值在0和1之间,是被解释变量,x1-x3是被解释变量)%tobit回归
sktest e %残差正态性检验 p>0.05则接受原假设,即服从正态分布; %% sktest是基于变量的偏度和斜度(正态分布的偏度为0,斜度为3)swilk x %基于Shapiro-Wilk检验
means %返回三种平均值 di normprob(1.96)di invnorm(0.05)di binomial(20,5,0.5)di invbinomial(20,5,0.5)di tprob(10,2)di invt(10.0.05)di fprob(3,27,1)di invfprob(3,27,0.05)di chi2(3,5)di invchi2(3,0.05)stack x y z,into(e)%把三列合成一列 xpose,clear %矩阵转置
append using d:917.dta %把已打开的文件(x y z)跟0917里的(x y z)合并,是竖向合并,即观察值合并;
merge using D:917.dta %把已打开的文件(x y z)跟0917里的(a b)合并,是横向合并,即变量合并; format x %9.2e %科学记数 format x %9.2f %2位小数
%产生随机数
%1 产生20个在(0,1)区间上均匀分布的随机数uniform()set seed 100 set obs 20 gen r=uniform()list % clear 清除内存
set seed 200 设置种子数为 200 set obs 20 设置样本量为 20 range no 1 20 建立编号 1 至 20 gen r=uniform()产生在(0,1)均匀分布的随机数 gen group=1 设置分组变量 group 的初始值为 1 sort r 对随机数从小到大排序
replace group=2 in 11/20 设置最大的 10 个随机数所对应的记录
为第2组,即:最小的10个随机数所
对应的记录为第1组 sort no 按照编号排序
list 显示随机分组的结果 也可以list if group==1和list no if group==1 %2 产生10个服从正态分布N(100,6^2)的随机数invnorm(uniform())*sigma+u clear 清除内存
set seed 200 设置种子数为 200 set obs 10 设置样本量为 10 gen x=invnorm(uniform())*6+100 产生服从 N(100,6^2)的随机数 list 画图
注意有些图前面要加 histogram 直方图 line 折线图 scatter 散点图
scatter y x,c(l)s(d)b2(“(a)”)graph twoway connected y x 连点图
graph bar(sum)var2,over(var1)blabel(total)%条形图.graph bar p52 p72,by(d).graph bar p52 p72,over(d).graph bar p52 p72,by(d)stack.graph bar p52 p72,over(d)stack ////////////数据如下 %d p52 p72 %1 163.2 27.4 %2 72.5 83.6 %3 57.2 178.2 histogram x,bin(8)norm %画直方图,加正态分数线
graph pie a b o ab if area==1,plabel(_all percent)%画饼图 graph pie var2, over(var1)plabel(_all percent)%饼图 graph pie p52 p72,by(d)%饼图 graph box y1 %箱体图 qnorm x %qq图 lfit y x %回归直线
graph matrix gender economy math 多变量散点图
line yhat x||scatter y x,c(.l)s(O.)xline(12)yline(5.4)%线形图&散点图