【正文】
”進行hausman檢驗)hausman twosls ols,alleqs(對所有方程一起進行檢驗)檢驗忽略變量(模型的RESET):reg y x1 x2 x3estat ovtest滯后變量的制取對變量y滯后一期:gen y_l1=y[_n1]滯后兩期:gen y_l2=y[_n2]以此類推。制取樣本序號:gen id=_n獲得樣本總量:gen id=_N時間序列回歸:回歸元嚴格外生時AR(1)序列相關(guān)的檢驗reg y x1 x2predict u,residgen u_1=u[_n1]reg u u_1,noconstant回歸之后,u_1的序數(shù)如果不異于零,則該序列不相關(guān)用DurbinWatson Statistics檢驗序列相關(guān):tsset year @(對時間序列回歸中代表時間的變量進行定義)@reg y x1 x2dwstat @(求出時間序列回歸的DW值)@durbina @(對該回歸是否具有序列相關(guān)進行檢驗,H0為無序列相關(guān),可根據(jù)chi2值求出P值)@durbina,small @(small可以根據(jù)F值求出P值,以代替chi2值)@durbina,force @(讓檢驗?zāi)茉趓obust、neway之后進行)@durbina,small lag(1/10) @(lag可以求出更高階滯后的序列相關(guān),如本例中可求出1到10階的序列相關(guān))@durbina,robust lag(1/10) @(robust可進行異方差—穩(wěn)健性回歸,避免未知形式的異方差)@bgodfrey @(利用BreuschGodfrey test求出高階序列相關(guān))@bgodfrey,small lag(1/10)數(shù)據(jù)調(diào)查:survey data源數(shù)據(jù):dataset文件夾中的svydata步驟:定義survey datasvyset psuid [pweight=finalwgt], strata(stratid)——定義primary sampling unit為psuid。可能是測試的編號,1or2——定義pweight為finalwgt——定義stratum identifer為stratid??赡苁菧y試中被試的編號,1to31生成malegen male= (sex==1) if !missing(sex)——當sex不缺失且等于1時,male=sex生成行變量為highbp,列變量為sizplace的表格svy, subpop(male): tabulate highbp sizplace, col obs pearson lr null wald——subpop規(guī)定了以male為數(shù)據(jù)調(diào)查的范圍——tabulate highbp sizplace表示繪制行變量為highbp,列變量為sizplace的表格——col表示每一列的加總為100%,row表示每一行的加總為100%,cell表示橫縱所有單元格的加總為100%——obs表示列出每個單元格的樣本量,se表示列出每個單元格的標準誤,ci表示列出每個單元格的置信區(qū)間——pearson表示求取pearson39。s chisquired,皮爾遜的卡方檢定——lr表示求取likelihood ratio——null表示求取nullbased statistics——wald表示求取adjusted wald,llwald表示求取adjusted loglinear Wald,noadjust表示求取unadjusted Wald statisticssvy:mean x1 x2 x3——對xxx3求取mean、se和ci簡單的tabulate twoway(不用svyset就可執(zhí)行)tab2 y x,col chi2 exact lr——col、cell、row等均可換用,chi2指的是Pearson39。s chisquared、exact指的是fisher exact test、lr指的是likelihoodratio chisquaredsvy的其他用法:svy:reg y x建立人工數(shù)據(jù)集:創(chuàng)建一個包含從獨立標準正態(tài)分布中抽取的2000個觀察案例和三個隨機ZZZ3,并分別定義他們的平均值和標準差。matrix m=(0,2,3) ——定義三個變量的平均值matrix sd=(1,.5,2) ——定義三個變量的標準差drawnorm z1 z2 z3,n(2000) means(m) sds(sd) ——創(chuàng)建樣本量為2000,均值和標準差符合上面定義的數(shù)據(jù)集補充:除了定義均值和標準差之外,還可定義相關(guān)矩陣和協(xié)方差矩陣等。logit回歸logit y x1 x2 x3——y必須為二分變量glogit outedata populationdata x1 x2 x3——outedata為目標樣本總量,populationdata為觀測樣本總量,outedata/populationdata的值便是一個概率,相當于logit命令中的y面板數(shù)據(jù)(Panel Data)基本套路:xtreg y x1 x2,reest store rextreg y x1 x2,feest store fehausman re fe——如果hausman檢驗的結(jié)果為顯著,則采用固定效應(yīng)(fe)模型,不顯著,則選取隨機效應(yīng)(re)模型隨機效應(yīng)的檢驗:xtreg y x1 x2,rexttest0xttest1——xttest1是xttest0的擴展,若這xttest0的結(jié)果為顯著,則采用隨機效應(yīng)(re)模型xttest1的假設(shè)是沒有隨機效應(yīng)和/或沒有序列相關(guān),它的七個結(jié)果分別表示:1) LM Test for random effects, assuming no serial correlation(假設(shè)沒有序列相關(guān)情況下對隨機效應(yīng)進行LM檢驗)2) Adjusted LM test for random effects, which works even under serialcorrelation(假設(shè)有序列相關(guān)的情況下對隨機LM檢驗)3) One sided version of the LM test for random effects(假設(shè)沒有序列相關(guān)的情況下對隨機效應(yīng)進行單邊檢驗)4) One sided version of the adjusted LM test for random effects(假設(shè)有序列相關(guān)的情況下對隨機效應(yīng)進行單邊檢驗)5) LM test for firstorder serial correlation, assuming no random effects(假設(shè)沒有隨機效應(yīng)的情況下對一階序列相關(guān)進行檢驗)6) Adjusted test for firstorder serial correlation, which works even underrandom effects(假設(shè)有隨機效應(yīng)的情況下對一階序列相關(guān)進行檢驗)7) LM Joint test for random effects and serial correlation(隨機效應(yīng)和序列相關(guān)的聯(lián)合檢驗)固定效應(yīng)模型,可采用廣義最小二乘法(gls)進行估算,也可采用固定效應(yīng)方程(fe):xtserial y x1 x2xtgls y x1 x2xttest2xttest3——xtserial用于檢驗固定效應(yīng)模型中的一階序列自相關(guān),可通用于xtgls和fe之前——xttest2用于檢驗不同廠商的相似性,若顯著則各廠家的截面相似,可通用于xtgls和fe之后——xttest3用于檢驗固定效應(yīng)模型中的異方差問題,若顯著則有異方差,可通用于xtgls和fe之后