*This file is for education purpose *Only for students in Khon Kaen University * *The original do-file is mus03p1reg.do November 25 2008 for Stata version 10.1 /* * STATA Program * copyright C 2008 by A. Colin Cameron and Pravin K. Trivedi * used for "Microeconometrics using Stata" * by A. Colin Cameron and Pravin K. Trivedi (2008) * Stata Press */ **************************************************************************** * *To run you need files *mus03data.dta in your directory * *To change your current directory go to *File > Change working directory > * *Then, choose a folder you want to work on *Add you mus03data.dta to your chosen folder * **************************************************************************** capture log close log using refresh.txt, text replace ************ DATA SUMMARY STATISTICS *************************************** * Variable description for medical expenditure dataset * use mus03data.dta describe totexp ltotexp posexp suppins phylim actlim totchr age female income * Summary statistics for medical expenditure dataset summarize totexp ltotexp posexp suppins phylim actlim totchr age female income * Detailed summary statistics of a single variable summarize totexp, detail * Two-way table of frequencies table female totchr * Two-way table with row and column percentages and Pearson chi-squared tabulate female suppins, row col chi2 * Three-way table of frequencies table female totchr suppins * One-way table of summary statistics table female, contents(N totchr mean totchr sd totchr p50 totchr) * Two-way table of summary statistics table female suppins, contents(N totchr mean totchr) * Summary statistics obtained using command tabstat tabstat totexp ltotexp, stat (count mean p50 sd skew kurt) col(stat) *********** BASIC REGRESSION ANALYSIS *********************************** *Question: What determines health care expenditures of elderly? ***************************************************************** * Pairwise correlations for dependent variable and regressor variables correlate ltotexp suppins phylim actlim totchr age female income * OLS regression with heteroskedasticity-robust standard errors regress ltotexp suppins phylim actlim totchr age female income, vce(robust) /* Interpretation: totchr: The number of chronic problem increases health care expenditure by 37.6%. income: The standard deviation of income is 22. A 1-standard deviation in income increases medical expenditure by 0.055 (22x0.0025), or 5.5%. suppins: With supplement insurance, medical expenditure increases by 29.2% (e0.256-e0). What you need to pay attention includes: F – test, R-squared and t-test of each coefficients. */ * Display stored results and list available postestimation commands ereturn list help regress postestimation /* Hypothesis test: impact of functional limitation and activity limitation on medical expenditure is statistically equal (H0: bphylim = bactlim). Use Wald test */ * Wald test of equality of coefficients quietly regress ltotexp suppins phylim actlim totchr age female /// income, vce(robust) test phylim = actlim /* Result p=0.6054 > 0.05, we do not reject H0. There is no statistically difference between the impacts of hylim and actlim. */ * Joint test of statistical significance of several variables test phylim actlim totchr * Add a user-calculated statistic to the table estimates drop REG1 REG2 quietly regress ltotexp suppins phylim actlim totchr age female /// income, vce(robust) estadd scalar pvalue = Ftail(e(df_r),e(df_m),e(F)) estimates store REG1 quietly regress ltotexp suppins phylim actlim totchr age female /// educyr, vce(robust) estadd scalar pvalue = Ftail(e(df_r),e(df_m),e(F)) estimates store REG2 esttab REG1 REG2, b(%10.4f) se scalars(F pvalue) mtitles keep(suppins) ****************************************************************************** /* Heteroskedasticity test: Breusch-Pagan Lagrange multiplier test estat hottest postestimation command: 1. Use y-hat as regressor. 2. Use all Xs as regressor. Reject homoscedasticity if chi-square < 0.05. */ * Heteroskedasticity tests using estat hettest and option iid quietly regress ltotexp suppins phylim actlim totchr age female income estat hettest, iid estat hettest suppins phylim actlim totchr age female income, iid * Information matrix test quietly regress ltotexp suppins phylim actlim totchr age female income estat imtest * Simulation to show tests have power in more than one direction clear all set obs 50 set seed 10101 generate x = runiform() // x ~ uniform(0,1) generate u = rnormal() // u ~ N(0,1) generate y = exp(1 + 0.25*x + 4*x^2) + u generate xsq = x^2 regress y x xsq * Test for heteroskedasticity estat hettest * Test for misspecified conditional mean estat ovtest