STATA實用學習筆記_第1頁
STATA實用學習筆記_第2頁
STATA實用學習筆記_第3頁
STATA實用學習筆記_第4頁
STATA實用學習筆記_第5頁
已閱讀5頁,還剩43頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

北京科技大學STATA應用學習摘錄

第一章STATA的基本操作一、設置內存容setmem500m,perm顯示輸入內容Display1Display“clive”顯示數據集結構describeDescribe/d編輯editEdit重命名變量Renamevar1var2顯示數據集內容list/browseListin1Listin2/10數據導入:數據文件是文本類型(.csv)insheet:.insheetusing“C:\DocumentsandSettings\Administrator\桌面\ST9007\dataset\Fees1.csv”,clear內存為空時才可以導入數據集,否則會出現(xiàn)(youmuststartwithanemptydataset)清空內存中的所有變量:.drop_all導入語句后加入“clear”命令。保存文件save“C:\DocumentsandSettings\Administrator\桌面\ST9007\dataset\Fees1.dta”save“C:\DocumentsandSettings\Administrator\桌面\ST9007\dataset\Fees1.dta”,replace打開及退出已存文件use1、.Use文件路徑及文件名,clear2、.Drop_all/.exit記錄命令和輸出結果(log)開始建立記錄文件:logusing"J:\phd\output.log",replace暫停記錄文件:logoff重新打開記錄文件:logon關閉記錄文件:logclose十一、創(chuàng)建和保存程序文件:(doedit,do)打開程序編輯窗口:doedit寫入命令保存文件,.do.運行命令:.do程序文件路徑及文件名十二、多個數據集合并為一個數據集(變量和結構相同)縱向合并appendinsheetusing"J:\phd\Fees1.csv",clearsave"J:\phd\Fees1.dta",replaceinsheetusing"J:\phd\Fees2.csv",clearappendusing"J:\phd\Fees1.dta"save"J:\phd\Fees1.dta",replace十三、橫向合并,在原數據集基礎上加上另外的變量merge1、insheetusing"J:\phd\Fees1.csv",clearsortcompanyidyearendsave"J:\phd\Fees1.dta",replacedescribeinsheetusing"J:\phd\Fees6.csv",clearsortcompanyidyearendmergecompanyidyearendusing"J:\phd\Fees1.dta"save"J:\phd\Fees1.dta",replacedescribe2、_merge==1obs.Frommasterdata_merge==2obs.Fromusingdata_merge==3obs.Frombothmasterandusingdata十四、幫助文件:help1、.Helpdescribe十五、描述性統(tǒng)計量1、summarizeincorporationyear單個summarizeincorporationyear-big6連續(xù)多個summarize_allorsimplysummarize所有2、更詳細的統(tǒng)計量summarizeincorporationyear,detail3、centilecentileauditfees,centile(0(10)100)centileauditfees,centile(0(5)100)4、tabulate不同類型變量的頻數和比例tabulatecompanytypetabulatecompanytypebig6,column按列計算百分比tabulatecompanytypebig6,row按行計算百分比tabcompanytypebig6ifcompanytype<=3,rowcol同時按行列和條件計算百分比5、計算滿足條件觀測的個數countifbig6==1countifbig6==0|big6==16、按離散變量排序,對連續(xù)變量計算描述性統(tǒng)計量:(1)bycompanytype,sort:summarizeauditfees,detail(2)sortcompanytypeBycompanytype:summarizeauditees十六、轉換變量1、按公司類型將公開發(fā)行股票公司賦值為1,其他為0genlisted=0replacelisted=1ifcompanytype==2replacelisted=1ifcompanytype==3replacelisted=1ifcompanytype==5replacelisted=.ifcompanytype==.十七、產生新變量genGeneratenewvar=表達式十八、數據類型1、數值型StoragetypeBytesMinMaxbyte1-127+100int2-32,767+32,740long4-2,147,483,6472,147,483,620float4-1.70141173319*10381.70141173319*1036double8-8.9884656743*103078.9884656743*103082、字符型StoragetypeBytesMaxlength(characters)str111str222…

str8080803、新建變量的過程中定義數據類型genstr3gender="male"listgenderin1/104、變量所占字節(jié)過長dropgendergenstr30gender="male"browsedescribegendercompressgender5、日期數據類型:%ddates,whichisacountofthenumberofdayselapsedsinceJanuary1,1960。(1)date(日期變量)genfye=date(yearend,"MDY")MDY應根據前面日期的排列順序而定,結果顯示的是距離1960年1月1日的天數listyearendfyein1/10(2)日期格式化%d(顯示fye變量為日期形式,但數值并未真正變動):formatfye%dlistyearendfyein1/10sumfye(3)利用日期天數求對應的年、月、日genyear=year(fye)genmonth=month(fye)genday=day(fye)listyearendfyeyearmonthdayin1/10(4)將三個分別表示年、月、日的變量合并為一個日期變量dropfyegenfye=mdy(month,day,year)formatfye%dlistyearendfyein1/10(5)將一個數值型的時間數據(20080131)轉變?yōu)镾T可識別的時間數據genyear=int(date/10000)genmonth=int((date-year*10000)/100)genday=date-year*10000-month*100listdateyearmonthdayin1/10genedate=mdy(month,day,year)formatedate%dlistedatedatein1/10十九、存貯統(tǒng)計量的內部變量R()sumauditfeesgenmeanadjaf=auditfees-r(mean)listmeanadjafin1/10SUM命令后常見的幾種R()值r(N)Numberofcasesr(sd)Standarddeviationr(sum_w)Sumofweightsr(min)Minimumr(mean)Arithmeticmeanr(max)Maximumr(var)Variancer(sum)Sumofvariable顯示這些變量值的命令sumauditfees,detailreturnlist二十、recode命令(PPT61)1、產生有多個值的變量的啞變量recoderecodeyear(min/1999=0)(2000/max=1),gen(yeardum)min/1999表示小于等于1999的值全部賦值為02000/max表示大于等于2000的值全部賦為1。2、對一個連續(xù)變量按一定值分為不同間隔的組recodegenassets_categ=recode(totalassets,100,500,1000,5000,20000,100000,1000000)。分組的值為每組的上限,包含該值。sortassets_categbyassets_categ:sumtotalassetsassets_categ對一個連續(xù)變量按一定值分為相同間隔的組autocodeautocode(variablename,#ofintervals,minvalue,maxvalue)forexample:genassets_categ=autocode(totalassets,10,0,10000)4、對一個連續(xù)變量按每組樣本數相同進行分組:xtilextileassets_categ=totalassets,nquantiles(10)每組樣本不一定完全相同二十一、一次性計算同一變量不同組別的均值:egen命令按公司類型先排序,再計算每一類型公司審計費用的均值并賦值給新變量:bycompanytype,sort:egenmeanaf2=mean(auditfees)count()mean()median()sum()二十二、_n和_N命令顯示每個觀測的序號并顯示總觀測數sortcompanyidfyecapturedropxgenx=_ncapturedropygeny=_Nlistcompanyidfyexyin1/302、分組顯示每個組中變量的序號和每組總的樣本數capturedropxysortcompanyidfyebycompanyid:genx=_nbycompanyid:geny=_Nlistcompanyidfyexyin1/303、創(chuàng)建新變量等于每個分組中變量的第一個值或最后一個值sortcompanyidfyebycompanyid:genauditfees_first=auditfees[1]bycompanyid:genauditfees_last=auditfees[_N]listcompanyidfyeauditfeesauditfees_firstauditfees_lastin1/304、創(chuàng)建新變量等于滯后一期或滯后兩期的值sortcompanyidfyebycompanyid:genauditfees_lag1=auditfees[_n-1]bycompanyid:genauditfees_lag2=auditfees[_n-2]listcompanyidfyeauditfeesauditfees_lag1auditfees_lag2in1/30二十三、轉變數據集結構:reshape不同數據庫的數據集結構不同:長型是指同一公司不同年度數據在不同的行。寬型數據是指同一數據不同年度數據在現(xiàn)一行。二者間的轉換可通過reshape命令來實現(xiàn)。需要注意的是,在轉換過程中對數據集是有要求的,一個公司只能有一個年度數據,否則會出錯。1、長型轉換為寬型:reshapewideyearendincorporationyearcompanytypesalesauditfeesnonauditfeescurrentassetscurrentliabilitiestotalassetsbig6fye,i(companyid)j(year)2、寬型轉換為長型:reshapelongyearendincorporationyearcompanytypesalesauditfeesnonauditfeescurrentassetscurrentliabilitiestotalassetsbig6fye,i(companyid)j(year)3、第二次轉換時命令可簡化:reshapewidereshapelong二十四、計算CAR的例子:已知股票日回報率,市場回報率,事件日,計算窗口期為三天的CAR。1、定義三天的窗口期:sorttickeredategenwindow=0ifeventdate<.(事件日為0)replacewindow=-1ifwindow[_n+1]==0&ticker==ticker[_n+1]replacewindow=1ifwindow[_n-1]==0&ticker==ticker[_n-1]2、計算AR和CARgenar=ret-vwretdgencar=ar+ar[_n-1]+ar[_n+1]ifwindow==0&ticker==ticker[_n+1]&ticker==ticker[_n-1]3、檢驗listtickeredateretvwretdarcarwindowifwindow<.二十五、means的T檢驗:1、檢驗總體上big6的審計收費有無顯著不同use"J:\phd\Fees.dta",cleargenlnaf=ln(auditfees)bybig6,sort:sumlnaftestlnaf,by(big6)2、分年度比較big6的審計收費有無顯著不同,加入byyear命令。genfye=date(yearend,"MDY")formatfye%dgenyear=year(fye)sortyearbyyear:ttestlnaf,by(big6)3、均值等于特定值得的T檢驗:sumlnafttestlnaf=2.1二十六、meadian的顯著性檢驗:1、獲取中位數的命令:bybig6,sort:sumlnaf,detailbybig6,sort:centilelnaf2、中位數檢驗:medianlnaf,by(big6)ranksumlnaf,by(big6)二十七、列聯(lián)表檢驗:1、創(chuàng)建列聯(lián)表的命令:tabulatecompanytypebig6,row第一個變量是表的最左側一列的項目,第二個變量是表的第一行的項目。2、兩變量之間的相關性檢驗:chi2tabulatecompanytypebig6,chi2row3、相關矩陣:pwcorrlnafbig6yearlisted4、列出相關矩陣并進行符號檢驗pwcorrlnafbig6yearlisted,sig5、在矩陣中列出觀測數pwcorrlnafbig6listedifyear==2000,sigobs二十八、創(chuàng)建一個不包含缺失值的數據集1、無缺失值的變量值為1,至少有一個的為0gensamp=1iflnaf<.&big6<.&year<.&listed<.2、缺失值的變量值表示同一行中缺失值的個數egenmiss=rmiss(lnafbig6yearlisted)summiss,detail二十九、圖形1、直方圖histogramincorporationyear,width(1)histogramincorporationyear,bin(147)width表示分一小份的寬度。bin表示分成的份數。改變寬度值可以使圖像看起來更合適。選擇起始點和間隔寬度:histlnafiflnaf>=0&lnaf<=5,width(0.25)選擇描述橫軸和縱軸的單位和數據標識:histlnafiflnaf>=0&lnaf<=5,width(0.25)xlabel(0(0.5)5)是否與正態(tài)分布一致:histlnafiflnaf>=0&lnaf<=5,width(0.25)normal2、散點圖(scatter)scatterlnaflnta第一個變量是縱軸,第二個變量是橫軸。twoway(scatterlnaflnta,msize(tiny))(lfitlnaflnta)在散點圖上加入最適合的一條直線。三十、縮尾處理winsor.winsorrev,gen(wrev)p(0.01)0.01代表去掉的百分數。Winsorrev,gen(wrev)h(5),5代表去掉的個數

第二章線性回歸內容簡介:2.1Thebasicideaunderlyinglinearregression2.2SinglevariableOLS2.3Correctlyinterpretingthecoefficients2.4Examiningtheresiduals2.5Multipleregression2.6Heteroskedasticity2.7Correlatederrors2.8Multicollinearity2.9Outlyingobservations2.10Medianregression2.11“Looping”2.1Thebasicideaunderlyinglinearregression1.殘差F為真實值,為預測值,ε為殘差。OLS回歸就是使殘差最小。2.基本一元回歸regressyx3.回歸結果的保存回歸結果的系數保存在_b[varname]內存變量中,常數項的系數保存在(_cons)內存變量中。4、預測值及殘差predictyhatpredictyres,residyres即為真實值得與預測值之差。5、殘差與X的散點圖twoway(scattery_resx)(lfity_resx)6、衡量估計系數準確程度:標準誤差。用樣本的標準偏差與系數之間的關系來衡量即T值(用系數除以標準差),同時P值是根據T值的分布計算出來的,表示系數落入標準對應上下限的可能性。前提是殘差符合以下假設:同方差:Homoscedasticity(i.e.,theresidualshaveaconstantvariance)獨立不相關:Non-correlation(i.e.,theresidualsarenotcorrelatedwitheachother)正態(tài)分布:Normality(i.e.,theresidualsarenormallydistributed)7、回歸結果包含的一些內容的意思各變差的自由度:FortheESS,df=k-1wherek=numberofregressioncoefficients(df=2–1)FortheRSS,df=n–kwheren=numberofobservations(=11-2)FortheTSS,df=n-1(=11–1)MS:變差除以自由度:Thelastcolumn(MS)reportstheESS,RSSandTSSdividedbytheirrespectivedegreesoffreedomR平方:TheR-squared=ESS/TSS調整的R平方:AdjR-squared=1-(1-R2)(n-1)/(n-k),消除了加入相關度不高解釋變量后R平方增加的不足。RootMSE=squarerootofRSS/n-k:模型的平均解釋能力TheF-statistic=(ESS/k-1)/(RSS/n-k):模型的總解釋能力2.3Correctlyinterpretingthecoefficients1、假如想檢驗big6的審計費用在公開發(fā)行和非公開發(fā)行公司之間的區(qū)別時,可用交互變量。Big6*listed.2、變量回歸系數的解釋(1)對連續(xù)變量系數的解釋:估計系數的經濟意義是指X對Y的影響,可以有不同的方法來衡量:一種是用X從25%變動到75%時Y的變動量。或X變動一個標準差時Y的變動。regauditfeestotalassetssumtotalassetsifauditfees<.,detailgenfees_low=_b[_cons]+_b[totalassets]*r(p25)genfees_high=_b[_cons]+_b[totalassets]*r(p75)sumfees_lowfees_high(2)對非連續(xù)變量的解釋一般使用0和1,而不是百分比。reglnafbig6genfees_nb6=exp(_b[_cons])genfees_b6=exp(_b[_cons]+_b[big6])sumfees_nb6fees_b62.4Examiningtheresiduals1、報告結果時,不僅用R平方來衡量顯著性,而且需要報告其他統(tǒng)計結果:istheresignificantheteroscedasticity?isthereanypatterntotheresiduals?arethereanyproblemsofoutliers?2、R2的使用:Gu(2007)pointsoutthat:econometriciansconsiderR2valuestoberelativelyunimportant(accountingresearchersputfartoomuchemphasisonthemagnitudeoftheR2)regressionR2sshouldnotbecomparedacrossdifferentsamplesincontrastthereisalargeaccountingliteraturethatusesR2stodeterminewhetherthevaluerelevanceofaccountinginformationhaschangedovertime。 TheR2tellsusnothingaboutwhetherourhypothesisaboutthedeterminantsofYiscorrect.3、適當使用resid來評估模型的優(yōu)劣。2.5Multipleregression1、判斷模型中有無忽略相關解釋變量:theorypriorempiricalstudies檢驗殘差和所預測的值之間是否獨立:genlisted=0replacelisted=1ifcompanytype==2|companytype==3|companytype==5reglnaflntabig6listedpredictlnaf_hat(求預測值,因變量的估計值)predictlnaf_res,resid(將殘差賦值給變量lnaf_res)twoway(scatterlnaf_reslnaf_hat)(lfitlnaf_reslnaf_hat)(檢驗殘差和預測值之間是否相關)3、另一種命令可以實現(xiàn)以上功能:reglnaflntabig6listedrvfplot2.6Heteroscedasticity(hettest)異方差性1、檢驗方差齊性的方法:回歸后使用hettest命令:regauditfeesnonauditfeestotalassetsbig6listedhettest方差齊性不會使系數有偏,但會使使系數的標準差有偏。產生的原因有可能是數據本身有界限,產生高的偏度。一些方差不齊可以通過取對數消除。當發(fā)現(xiàn)不齊性時使用Huber/White/sandwichestimator對標準差進行調整。STATA可以在回歸時加上robust來實現(xiàn)。regauditfeesnonauditfeestotalassetsbig6listed,robust加robust后的回歸系數相同,但標準差不同,T值變小,P值變大,F(xiàn)值變小,R2不變。2.7Correlatederrors(自變量相關)1、Theresidualsofagivenfirmarecorrelatedacrossyears(“timeseriesdependence”),面板數據(Inpaneldata),同一公司不可觀測的特性對不同年度都會產生一定的影響,這時就會使數據不獨立。therearelikelytobeunobservedcompany-specificcharacteristicsthatarerelativelyconstantovertime2、標準差會下偏,Thisproblemcanbeavoidedbyadjustingthestandarderrorsfortheclusteringofyearlyobservationsacrossagivencompany3、消除變量相關問題:在回歸中加入robustcluster()reglnaflntabig6listed,robustcluster(companyid)4、如何驗證同一公司不同年度數據的殘差的相關性reglnaflntapredictres,residkeepcompanyidyearressortcompanyidyeardropifcompanyid==companyid[_n-1]&year==year[_n-1]reshapewideres,i(companyid)j(year)browsepwcorrres1998-res20025、在使用面板數據時應注意:只用robust控制heteroscedasticity,而未用cluster()控制time-seriesdependence,T統(tǒng)計量也會上偏。如果heteroscedasticity也未控制,T統(tǒng)計量會上偏更嚴重。因此在使用面板數據時應加入robustcluster()option,otherwiseyour“significant”resultsfrompooledregressionsmaybespurious.2.8Multicollinearity1、什么情況下會產生多重共線性Wehaveseenthatwhenthereisperfectcollinearitybetweenindependentvariables,STATAwillhavetoexcludeoneofthem.Forexample,year_1+year_2+year_3+year_4+year_5=1reglnafyear_1year_2year_3year_4year_5,noconsSTATAautomaticallythrowsawayoneoftheyeardummiessothatthemodelcanbeestimatedEveniftheindependentvariablesarenotperfectlycollinear,therecanstillbeaproblemiftheyarehighlycorrelated2、后果:thestandarderrorsofthecoefficientstobelarge(i.e.,thecoefficientsarenotestimatedprecisely)thecoefficientestimatescanbehighlyunstable3、衡量方法:Variance-inflationfactors(VIF)可用來衡量是否存在多重共線性。reglnaflntabig6lnta1vifreglnaflntabig6vif多重共線性的嚴重程度:如果為10時可判斷為高,為20時可判斷為非常高。2.9Outlyingobservations1、異常值的衡量Cook’sDWecancalculatetheinfluenceofeachobservationontheestimatedcoefficientsusingCook’sDValuesofCook’sDthatarehigherthan4/Nareconsideredlarge,whereNisthenumberofobservationsusedintheregression2、異常值的計算reglnaflntabig6predictcook,cooksd(將cooksd的值賦給cook)sumcook,detailgenmax=4/e(N)(求max,e(N)是回歸過程中的內部已知變量)countifcook>max&cook<.去掉異常值后重新回歸reglnaflntabig6ifcook<=max5、用winsorize方法消除異常值:其缺點是Adisadvantagewith“winsorizing”isthattheresearcherisassumingthatoutlierslieonlyattheextremesofthevariable’sdistribution。winsorlnaf,gen(wlnaf)p(0.01)winsorlnta,gen(wlnta)p(0.01)sumlnafwlnaflntawlnta,detailregwlnafwlntabig62.10Medianregression1、中位數回歸是當存在異常值問題時使用。2、原理:OLS估計是盡量使殘差平方和最?。褐形粩祷貧w是盡量使thesumoftheabsoluteresiduals最小?;貧w方法:STATA將中位數回歸看作是quantileregressions的一個特例。qreglnaflntabig62.11“Looping”1、當多次用到一個命令集時,我們可以建立一個程序集,以program開頭,以forvalues引導的內容,以end結束。使用時只須輸入程序名“ten”即可執(zhí)行程序中的一引起命令集。Example:programten forvaluesi=1(1)10{ display`i' }end2、修改命令集:須首先刪除內存中的命令集:captureprogramdropten然后重新編寫。例子:利用JONES模型計算操控性應計。use"J:\phd\accruals.dta",cleargenone_sic=int(sic/1000)genncca=current_assets-cashgenndcl=current_liabilities-debt_in_current_liabilitiessortcikyeargench_ncca=ncca-ncca[_n-1]ifcik==cik[_n-1]gench_ndcl=ndcl-ndcl[_n-1]ifcik==cik[_n-1]genaccruals=(ch_ncca-ch_ndcl)/assets[_n-1]ifcik==cik[_n-1]genlag_assets=assets[_n-1]ifcik==cik[_n-1]genppe_scaled=ppe/assets[_n-1]ifcik==cik[_n-1]genchsales_scaled=(sales-sales[_n-1])/assets[_n-1]ifcik==cik[_n-1]genab_acc=.captureprogramdropab_accprogramab_accforvaluesi=0(1)9{captureregaccrualslag_assetsppe_scaledchsales_scaledifone_sic==`i'capturepredictab_acc`i'ifone_sic==`i',residreplaceab_acc=ab_acc`i'ifone_sic==`i'capturedropab_acc`i'}endab_acc

第三章因變量為非連續(xù)性變量時的回歸分析內容簡介:3.1WhynotOLS?3.2Thebasicideaunderlyinglogitmodels3.3Estimatinglogitmodels3.4Multinomialmodels3.5Ordinaldependentvariables3.6Countdatamodels3.7Tobitmodelsandintervalregression3.8Durationmodels3.1WhynotOLS?twostatisticalproblemsifweuseOLSwhenthedependentvariableiscategorical:ThepredictedvaluescanbenegativeorgreaterthanoneThestandarderrorsarebiasedbecausetheresidualsareheteroscedastic.InsteadofOLS,wecanusealogitmodel3.2Thebasicideaunderlyinglogitmodels1、Weneedtocreateavariablethat:將離散型的因變量轉變?yōu)榉螼LS的形式。hasaninfiniterange,reflectsthelikelihoodofchoosingabig6auditorversusanon-big6auditor.2、“oddsration”可實現(xiàn)上面的兩項要求:log(oddsration)具體例子:第一列為big6的可能性,第二列和第三列為優(yōu)勢比率,第四列為取自然對數后的值。4、L和P之間的轉換關系。5、似然函數:使用最大似然法估計(maximumlikelihood”estimation)6、回歸命令logit和logisticlogitreportsthevaluesoftheestimatedcoefficientslogisticreportstheoddsratios一般報告系數估計所以使用logit。7、模型的解釋能力參數:pseudo-R2和Chi2pseudo-R2=(ln(L0)-ln(LN))/ln(L0)=(-175224+146215)/-175224ln(L0)是第一個回歸值,ln(LN)是最后一個回歸值。Chi2=-2(ln(L0)-ln(LN))=-2*(-175224+146215)=580183.3Estimatinglogitmodels1、回歸模型logitbig6lntaage,robustcluster(companyid)加入robust命令是為了糾正異方差,加入cluster()是為了糾正相關性錯誤。2、預測因變量的可能性logitbig6lntaage,robustcluster(companyid)dropbig6hatpredictbig6hatsumbig6hat,detail用此命令產生的預測值為以下公式:另一種產生預測因變量可能性的方法:genbig6hat2=exp(big6hat1)/(1+exp(big6hat1))sumbig6hatbig6hat1big6hat23、產生預測因變量的值:genbig6hat1=_b[_cons]+_b[lnta]*lnta+_b[age]*agesumbig6hat1,detail另一種方法是predictbig6hat1,xb計算自變量變動對因變量可能性的影響:logitbig6lntaage,robustcluster(companyid)genbig10=exp(_b[_cons]+_b[lnta]*lnta+_b[age]*10)/(1+(exp(_b[_cons]+_b[lnta]*lnta+_b[age]*10)))genbig20=exp(_b[_cons]+_b[lnta]*lnta+_b[age]*20)/(1+(exp(_b[_cons]+_b[lnta]*lnta+_b[age]*20)))sumbig10big205、檢驗因變量與自變量之間單調性的方法:xtilelnta_categ=lnta,nquantiles(10)tabulatelnta_categ,gen(lnta_)logitbig6lnta_2-lnta_10age,robustcluster(companyid)6、另一種估計方法probitLogit把P(Y=1)轉換成0-1之間的數據,數據服從對數分布Probit把P(Y=1)轉換成0-1之間的數據,數據服從正態(tài)分布。似然函數為Thecoefficientstendtobelargerinprobitmodelsbutthelevelsofstatisticalsignificanceareoftensimilar例子:capturedropbig6hatbig6hat1logitbig6lntaage,robustcluster(companyid)predictbig6hatprobitbig6lntaage,robustcluster(companyid)predictbig6hat1pwcorrbig6hatbig6hat13.4Multinomialmodels(多項式模型)1、適用情況:因變量分為三個或以上分類,而且分類不排序,每一個分類都有1和0兩個變量。如果用logit模型分別回歸,將使回歸后合計的可能性不等于1。將公司類型分為三類gencotype1=0ifcompanytype==1|companytype==6replacecotype1=1ifcompanytype==4replacecotype1=2ifcompanytype==2|companytype==3|companytype==5將每類變量分為兩種情況genprivate=0replaceprivate=1ifcotype1==0genpublic_nontraded=0replacepublic_nontraded=1ifcotype1==1genpublic_traded=0replacepublic_traded=1ifcotype1==2用logit模型分單個變量進行回歸logitprivatelnta,robustcluster(companyid)predictprivate_hatlogitpublic_nontradedlnta,robustcluster(companyid)predictpublic_nontraded_hatlogitpublic_tradedlnta,robustcluster(companyid)predictpublic_traded_hat合計的可能性不等于1gensum_prob=private_hat+public_nontraded_hat+public_traded_hatsumsum_prob,detail2、多于2個分類時的因變量回歸:mprobit或mlogitMprobit時間長Mlogit時間短mprobitcotype1lnta,robustcluster(companyid)mlogitcotype1lnta,robustcluster(companyid)回歸后直接檢驗回歸系數是否相等:test[1=2]:lntatest[1=2]:_cons以上回歸時在三類中選擇系統(tǒng)默認的類別作為對比組,也可以人為設置對比組。mlogitcotype1lnta,baseoutcome(1)robustcluster(companyid)3.5Ordinaldependentvariables1、因變量排序模型回歸適用情況:Moregenerally,theordereddependentvariablemaytakeNpossiblevalues(Y=1,2,…,N)inwhichcasethereareN-1cut-offpoints:L=a0+a1X1+a2X2+eY=NifkN-1<L<+Y=N-1ifkN-2<LkN-1...Y=2ifk1<Lk2Y=1if-<Lk12、排序模型回歸ologitologitopinionreviewed_firm_also_reviewerlitigation_dummy,robustologitopinion1reviewed_firm_also_reviewerlitigation_dummy,robust以上兩模型回歸的結果相同,雖然因變量的值不一樣,但排序的大小順序一樣。3、回歸的結果:回歸的結果是cut值:Thesearethecut-offvalueskN-1,kN-2,...,k2,k1Y=NifkN-1<L<+Y=N-1ifkN-2<LkN-1....etc.Y=2ifk1<Lk2Y=1if-<Lk1Anotherdifferenceisthatthereisnointercepttermintheorderedlogitandorderedprobitmodels.4、排序數據的另一種回歸方法:oprobitoprobitopinionreviewed_firm_also_reviewerlitigation_dummy,robustNoticethattheologitandoprobitresultsarequiteclosetoeachotherusuallyitdoesn’tmakemuchdifferencewhetheryouuseorderedlogitororderedprobit.3.6Countdatamodels1、適用情況:計數模型適用于因變量是非負的離散數,且數據有實際的意義。比如:considerthenumberoffinancialanalyststhatfollowagivencompanyifthecompanyisnotfollowedbyanyanalysts,Y=0ifthecompanyisfollowedbyoneanalyst,Y=1ifthecompanyisfollowedbytwoanalysts,Y=2ifthecompanyisfollowedbytwoanalysts,Y=3此種數據無法使用OLS回歸,因為因變量無法滿足數據是在負無窮到正無窮之間,因為只能取非負數,同時要求因變量是連續(xù)變量,而計數模型的因變量是離散的。2、適用的回歸模型Twodistributionsthatfulfillthecriteriaofhavingnon-negativediscreteintegervaluesarethe“Poisson”andthe“negativebinomial”.thenegativebinomial(nbreg)thePoisson(poisson)3、實際中計數模型的例子:ThenumberofR&DpatentsawardedThenumberofairlineaccidentsThenumberofmurdersThenumberoftimesthatmainlandChinesepeoplehavevisitedSingaporeThenumberofweaknessesfoundbypeerreviewersatauditfirms4、模型的選擇:(1)POISSON模型:ThePoissondistributionismostoftenusedtodeterminetheprobabilityofxoccurrencesperunitoftime。E.g.,thenumberofmurdersperyearThebasicassumptionsofthePoissondistributionareasfollows:ThetimeintervalcanbedividedintosmallsubintervalssuchthattheprobabilityofanoccurrenceineachsubintervalisverysmallTheprobabilityofanoccurrenceineachsubintervalremainsconstantovertimeTheprobabilityoftwoormoreoccurrencesineachsubintervalmustbesmallenoughtobeignoredAnoccurrenceornonoccurrenceinonesubintervalmustnotaffecttheoccurrenceornonoccurrenceinanyothersubinterval(thisistheindependenceassumption).滿足條件下的例子:TheprobabilityofamurderoccurringduringanygivenminuteissmallTheprobabilityofamurderoccurringduringanygivenminuteremainsconstantduringtheyearTheprobabilityofmorethanonepersonbeingmurderedduringanygivenminuteisverysmallThenumberofmurdersinanygiventimeperiodisindependentofthenumberofmurdersinanyothertimeperiod.參數的估計:TheonlyparameterneededtocharacterizethePoissondistributionisthemeanrateatwhicheventsoccur。“incidencerate”,F(xiàn)orexample,canbetheaveragenumberofmurderspermonthortheaveragenumberofanalystspercompanyPOISSON分布的概率函數:如果已知每月的犯罪數為2,求每月有3起犯罪的概率。模型特點:模型只有一個參數λ,發(fā)生率可用右式估計。命令:controlforheteroscedasticityusingtherobustoptionpoissonweaknessesreviewed_firm_also_reviewerlitigation_dummy,robustpaneldataset(itisn’t)youwouldalsoneedtocontrolfortime-seriesdependenceusingthecluster()option缺點:Unobservedheterogeneityinthedata(e.g.,omittedvariables)willoftencausethevariancetoexceedthemean(aphenomenonknownas“overdispersion”).回歸后檢驗:回歸后馬上用poisgof命令,檢驗是否顯著,如顯著則無法使用,而須使用Thenegativebinomial,該模型無須assumethatthemeanandvarianceofthedistributionarethesame(2)thenegativebinomial模型:nbregweaknessesreviewed_firm_also_reviewerlitigation_dummy,robust(cluster())回歸結果的α顯著,說明POISSON模型不適用。3.7Tobitandintervalregressionmodels1、適用的數據類型:censoring(ortruncation)ofthedependentvariable.當觀眾數大于座位數時,觀測不到。2、選擇模型:Thecensoringproblemcanbesolvedbyestimatinga“tobit”modelThetobitmodelissomewhatsimilar:Y*=a0+a1X+eY=0if-<Y*0Y=Y*if0<Y*<+TheY*andYvariablesarebothobservedwhentheyaregreaterthanzero(Y*isunobservedwhenY=0)Boththeprobitandtobitmodelsassumethattheerrors(e)arenormallydistributed.3、例子:Recallthatinourfeedataset,thenonauditfeesvariableisleft-censoredatzerobecausemanycompanieschoosenottopurchaseanynon-auditservices。ThisphenomenonislikesomeindividualschoosingnottopurchaseanycigaretteswhenthepriceexceedsP0genlnta=ln(totalassets)egenmiss=rmiss(lnnaflnta)(當lnnaflnta為miss時,miss為1)tobitlnnaflntaifmiss==0,ll(0)(ll(數字)表示左邊截取的數據,ul(數字)表示右邊截取的數字。)tobitlnnaflntaifmiss==0,ll(此命令與上命令功能相同)回歸完成后可以用命令顯示有多少數據censoried.countifmiss==0&lnnaf==0countifmiss==0&lnnaf>04、當左右兩邊均截取以后,也可使用tobit模型genlnnaf1=lnnafreplacelnnaf1=5iflnnaf>5&lnnaf!=.tobitlnnaf1lntaifmiss==0,ll(0)ul(5)tobitlnnaf1lntaifmiss==0,llul(如果截取數字是樣本中的最大和最小值不用列出,系統(tǒng)會自動選取)。tobitlnnaflntaifmiss==0,llul(5)robustcluster(companyid)(控制異方差和時間序列不獨立)3.8Durationmodels(生存模型)1、適用數據:因變量測試某一事件持續(xù)的時間。例如:Durationoflife(medical,engineering)howlongdopeoplelivefor?howlongdomachineslast?Durationofunemployment(economics)howlongdopeopleremainunemployed?forexample,wemaybeinterestedinhowretrainingschemesaffectthedurationofunemploymentDurationofCEOtenure(management)howlongdoestheCEOstayatthesamecompany?Durationofauditor-companytenure(accounting)howlongdothecompanyandauditfirmstaytogether?2、度量變量:The“hazardrate”,h(t),istheprobabilitythattheeventwilloccurinperiodt,giventhatithasnotoccurreduptotimet.3、使用命令stsettimevaruse"J:\phd\kva.dta",clearliststsetfailtime該語句產生四個內部變量:顯示變量:listfailtime_st_d_t_t0The_stvariableisadummyequaltooneforobservationswhosedatahasbeenstset(e.g.,therewouldhavebeensomezerovaluesifwehadexcludedsomeobservationsusingtheifqualifier)The_dvariable是否改變狀態(tài)The_tvariable生存時間The_t0variable生存起始點,默認為04、用Coxproportionalhazardsmodel估計命令:stcoxstcoxloadbearings(loadbearings兩個變量是影響生命的兩個因素)Thereportedhazardratiosaretheexponentialsofthecoefficients.Thehazardratioforload=1.52647=exp(a1)wherea1isthecoefficientonloada1=ln(1.52647)=0.4229578Thecoefficientonbearings=ln(0.0636433)=-2.754461Theloadcoefficientissignificantlypositiveimplyingthatthemachinesfailmorequickly(higherhazardrate)whentheyareundergreaterstressThebearingscoefficientissignificantlynegativeimplyingthatthemachinesfaillessquickly(lowerhazardrate)whentheyusethenew-typeofbearing.如果想讓系統(tǒng)報告系數而不是H(T)系數,可使用以下命令stcoxloadbearings,nohr解決ties問題的模型之一:breslowTheBreslowmethodisveryfastandisthedefaultmethodthatSTATAusesforresolvingties.如果生存時間相同時,就形成一個ties.命令集:stcoxloadbearings,breslowstcoxloadbearings,efron解決ties問題的模型之二:efron該方法比上一個方法更準確,但用時較長。將兩個同樣的死亡時間各分0.5的可能性。當存在censoring時,即并不是所且有的樣本都死亡時,需要在命令中加選項。stsetfailtime,failure(failed)ThefailtimevariablegivesthetimeoffailureorcensoringThefailedvariableindicateswhetherfailureorcensoringoccurredSTATAassumescensoringiffailedequalszeroorissettomissing以上均是處理一個事件只占一行的情況,當事件某一特性改變時,就需要多行來描述。這時需要在告訴系統(tǒng)以下數據為生存數據的命令中加入選項,事件代碼stsett,id(patid)failure(died)當Left-censoringoccurs,這時需在說明生存命令中加入開始時間變量stsetend,id(id)failure(died)enter(begin)當中間部分時間的數據缺失時的處理:需要說明死亡時間、變量標識,死亡標識,開始時間。stsetend,id(id)failure(died)enter(begin)為消除heteroscedasticityandtime-seriesdependence,可以在回歸命令的最后加上robust和cluster().stcoxx1,robustcluster(id)小結:根據因變量的類型選擇不同的回歸模型Dependentvariable(Y)ExamplesEstimationmethod(s)STATAcommandContinuous(-<Y<+)LogofauditfeesStockreturnsCostofcapitalOLSQuantileregressionregressqregBinary(Y=0,1)Listed/NotlistedBig6/Non-Big6auditorProbitLogitprobitlogitDiscreteandunordered(Y=0,1,2,..)Methodoftransport(train,bus,car,bicycle)Typeofcompany(private,publicunquoted,quoted)MultinomiallogitMultinomialprobitmlogitmprobitDiscreteandordered(Y=0,1,2,..)Typeofpeerreviewreport(adverse,modified,unmodified)OrderedprobitOrderedlogitoprobitologitDependentvariable(Y)ExamplesEstimationmethod(s)STATAcommandDiscretecountdata(Y=0,1,2,…)NumberofweaknessesdisclosedinpeerreviewreportPoissonNegativebinomialpoissonnbregContinuousbutcensored(kLY<kH)Non-auditfeesFootballattendanceTobittobitDurationdata(oftencensored)kLY<kHDurationofunemploymentCEOtenureCompanysurvivalCoxproportionalhazardsstcox

第四章面板數據主要內容:4.1Thebasicidea4.2Linearregression4.3Logitandprobitmodels4.4Othermodels4.1Thebasicidea1、面

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論