benjann / estout

Stata module to make regression tables
http://repec.sowi.unibe.ch/stata/estout/index.html
MIT License
71 stars 18 forks source link

Is that possible to add an option to report one-sided tests? #43

Closed fredericky123 closed 2 years ago

fredericky123 commented 2 years ago

Sometimes, I need to report the exact one-sided p values in the tables, I know pvalue(name) to specify the p-values used, however, calculating the one-sided p values for all coefficients seems difficult for me, could you please add such option?

Thanks so much! Sincerely!

NilsEnevoldsen commented 2 years ago

estout does not estimate results, it only tabulates estimated results. This sort of computation is outside the scope of estout.

Secondarily, it is unusual to have one-sided tests in regression tables. Are you sure they are appropriate in your case?

fredericky123 commented 2 years ago

Thanks Nils, one-sided tests only occur under specific circumstances. You are right, since esttab don't compute the estimates, I should calculate it by myself. Thanks again!

fredericky123 commented 2 years ago

I just thought, can use estadd to calculate the one-sided p values?

fredericky123 commented 2 years ago

Hi @NilsEnevoldsen Nils, Could you please help me to check what's wrong with the syntax below? The one-sided p values for model 1 was wrong, for model 2 was correct.

capture program drop estadd_bstdy
program estadd_bstdy, eclass
    tempname bstdy
    matrix `bstdy' = e(b)
    quietly summarize `e(depvar)' if e(sample)
    matrix `bstdy' = `bstdy' / r(sd)
    ereturn matrix bstdy = `bstdy'
end
sysuse auto,clear
eststo clear
eststo: quietly regress price weight mpg
eststo: quietly regress price weight mpg foreign
estadd bstdy : *

capture program drop estadd_oneSidedP
program estadd_oneSidedP, eclass
    tempname oneSidedP
    matrix `oneSidedP' = r(table)
    matrix `oneSidedP' = `oneSidedP'/2
    ereturn matrix oneSidedP = `oneSidedP'
end
estadd oneSidedP : *
esttab ,cells("b(fmt(3)) p(fmt(3))" se(fmt(3) par)) 
esttab , cells("b(fmt(3)) oneSidedP[4](fmt(3))" se(fmt(3) par))
fredericky123 commented 2 years ago

@benjann Hi Ben, could you please help me out? Is that a bug or a wrong syntax about this?

benjann commented 2 years ago

You need to replay the estimation command within the estadd subroutine so that the correct r(table) is generated. About as follows:

capture program drop estadd_oneSidedP
program estadd_oneSidedP, eclass
    quietly `e(cmd)' // call the command without option to generate r(table)
    tempname P
    matrix `P' = r(table)
    matrix `P' = `P'[4, 1...] // select the row containing the pvalues
    matrix `P' = `P'/2
    ereturn matrix oneSidedP = `P'
end

sysuse auto,clear
eststo clear
eststo: quietly regress price weight mpg
eststo: quietly regress price weight mpg foreign
estadd oneSidedP : *
esttab ,cells("b(fmt(3)) p(fmt(3))" se(fmt(3) par)) 
esttab , cells("b(fmt(3)) oneSidedP(fmt(3))" se(fmt(3) par))

Of course computing one-sided pvalues as "two-sided pvalue / 2" is only appropriate if the effect is in the right direction (i.e. in the direction of the hypothesis). Possibly the routine should be improved such that the direction of the hypothesis can be specified for each coefficient...

ben

fredericky123 commented 2 years ago

I see. Thanks so much!