version 10.0 log using chap06, replace use andy, clear * ------------------------------------------- * The following block estimates Andy's sales * and uses the difference in SSE to test * a hypothesis using an F-statistic * ------------------------------------------- * Unrestricted Model regress sales price advert scalar sseu = e(rss) scalar df_unrest = e(df_r) * Restricted Model regress sales advert scalar sser = e(rss) scalar df_rest = e(df_r) scalar J = df_rest - df_unrest * F-statistic, critical value, pvalue scalar fstat = ((sser -sseu)/J)/(sseu/(df_unrest)) scalar crit1 = invFtail(J,df_unrest,.05) scalar pvalue = Ftail(J,df_unrest,fstat) scalar list sseu sser J df_unrest fstat pvalue crit1 * ------------------------------------------- * Here, we use Stata's test statement * to test hypothesis using an F-statistic * Note: Three versions of the syntax * ------------------------------------------- regress sales price advert test price test (price=0) test (_b[price]=0) * The t-test regress sales price advert scalar t2 = (_b[price]/_se[price])^2 scalar list t2 * ------------------------------------------- * Overall Significance of the Model * Uses same Unrestricted Model as above * ------------------------------------------- * Unrestricted Model (all variables) regress sales price advert scalar sseu = e(rss) scalar df_unrest = e(df_r) * Restricted Model (no explanatory variables) regress sales scalar sser = e(rss) scalar df_rest = e(df_r) scalar J = df_rest - df_unrest * F-statistic, critical value, pvalue scalar fstat = ((sser -sseu)/J)/(sseu/(df_unrest)) scalar crit2 = invFtail(J,df_unrest,.05) scalar pvalue = Ftail(J,df_unrest,fstat) scalar list sseu sser J df_unrest fstat pvalue crit2 * ------------------------------------------- * Extended Model * ------------------------------------------- * Unrestricted Regression gen a2 = advert*advert regress sales price advert a2 scalar sseu = e(rss) scalar df_unrest = e(df_r) * Restricted Regression regress sales price scalar sser = e(rss) scalar df_rest = e(df_r) scalar J = df_rest - df_unrest * F-statistic, critical value, pvalue scalar fstat = ((sser -sseu)/J)/(sseu/(df_unrest)) scalar crit = invFtail(J,df_unrest,.05) scalar pvalue = Ftail(J,df_unrest,fstat) scalar list sseu sser J df_unrest fstat pvalue crit * ------------------------------------------- * Extended Model: * Repeat above test using built-in * test statements * ------------------------------------------- regress sales price advert a2 * ------------------------------------------- * Equivalent forms of test of linear restrictions * ------------------------------------------- test (_b[advert]=0)(_b[a2]=0) test (advert=0)(a2=0) test advert a2 * ------------------------------------------- * Optimal Advertising * Uses both syntaxes for test * ------------------------------------------- * Equivalent to Two sided t-test regress sales price advert a2 test _b[advert]+3.8*_b[a2]=1 test advert+3.8*a2=1 * t stat for Optimal Advertising lincom _b[advert]+3.8*_b[a2]-1 lincom advert+3.8*a2-1 scalar t = r(estimate)/r(se) scalar pvalue2tail = 2*ttail(e(df_r),t) scalar pvalue1tail = ttail(e(df_r),t) scalar list t pvalue2tail pvalue1tail * t stat for Optimal Advertising (alternate method) gen xstar = a2-3.8*advert gen ystar = sales - advert regress ystar price advert xstar scalar t = (_b[advert])/_se[advert] scalar pvalue = ttail(e(df_r),t) scalar list t pvalue * Joint Test regress sales price advert a2 test (_b[advert]+3.8*_b[a2]=1) (_b[_cons]+6*_b[price]+1.9*_b[advert]+3.61*_b[a2]= 80) * ------------------------------------------- * Nonsample Information * ------------------------------------------- use beer, clear gen lq = log(Q) gen lpb = log(PB) gen lpl = log(PL) gen lpr = log(PR) gen li = log(I) constraint 1 lpb+lpl+lpr+li=0 cnsreg lq lpb lpl lpr li, c(1) * ------------------------------------------- * MROZ Examples * ------------------------------------------- use edu_inc, clear regress faminc he we regress faminc he * ------------------------------------------- * Stata uses the estat ovtest following * a regression to do a RESET(3) test. * ------------------------------------------- regress faminc he we kl6 estat ovtest regress faminc he we kl6 predict yhat gen yhat2=yhat^2 gen yhat3=yhat2*yhat summarize faminc he we kl6 *------------------------------- * Data are ill-conditioned * Reset test won' work here * Try it anyway! *------------------------------- regress faminc he we kl6 yhat2 test yhat2 regress faminc he we kl6 yhat2 yhat3 test yhat2 yhat3 *---------------------------------------- * Drop the previously defined predictions * from the dataset *---------------------------------------- drop yhat yhat2 yhat3 *-------------------------------- * Recondition the data by * scaling FAMINC by 10000 * ------------------------------- gen faminc_sc = faminc/10000 regress faminc_sc he we kl6 predict yhat gen yhat2 = yhat^2 gen yhat3 = yhat2*yhat summarize faminc_sc faminc he we kl6 yhat yhat2 yhat3 regress faminc_sc he we kl6 yhat2 test yhat2 regress faminc_sc he we kl6 yhat2 yhat3 test yhat2 yhat3 * Extraneous regressors regress faminc he we kl6 x5 x6 * ------------------------------------------- * Cars Example * ------------------------------------------- use cars, clear summarize corr regress mpg cyl regress mpg cyl eng wgt test cyl test eng test eng cyl * Auxiliary regressions for collinearity * Check: r2 >.8 means severe collinearity regress cyl eng wgt scalar r1 = e(r2) regress eng wgt cyl scalar r2 = e(r2) regress wgt eng cyl scalar r3 = e(r2) scalar list r1 r2 r3 log close translate chap06.smcl chap06.txt, replace