Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Outreg2 - Use addstat to display statistics from lstat and fitstat

    Greetings,
    I want to use outreg2 to report various logit model results including: AIC, BIC, log-likelihood for full model, chi-squared stat, Nagelkerke/C-U R-squared, and the percent predicted correctly. I am able to get most of these (except the percent predicted "correctly" using outreg2 using the following code:
    Code:
    logit y x1 x2 x3 , r
    est store M1, title (Model 1)
    fitstat
    outreg2 using Table.xls, dec(3) addstat(AIC, `r(stataaic)', BIC, `r(statabic)', Log-Likelihood Full Model, `r(ll)', chi-square test, `e(chi2)', Nagelkerke_R2, `r(r2_cu)') groupvar(x1 x2 x3) ctitle("Model 1") replace
    Alternatively, I can get the percent predicted using this code:

    Code:
    logit y x1 x2 x3 , r
    est store M1, title (Model 1)
    lstat
    outreg2 using Table_IndependencePreferences.xls, dec(3) addstat(Percent Correct, `r(P_corr)') groupvar(x1 x2 x3) ctitle("Model 1") replace
    I cannot, however, use fitstat and lstat without the return from one overwriting the other. So I tried the following to save the lstat results as a local macro and then run fitstat and then report both but I continue to get a "syntax error" (r198).

    Code:
    logit y x1 x2 x3 , r
    est store M1, title (Model 1)
    lstat
    mat lstats = r(S)
    local PctCorr: display %4.1f lstats[1,9]
    fitstat
    outreg2 using Table_IndependencePreferences.xls, dec(3) addstat(AIC, `AIC', Pseudo R-squared, `e(r2_p)',chi-square test, `e(chi2)', PctCorr, `PctCorr') groupvar(x1 x2 x3) ctitle("Model 1") replace
    I am suspicious that fitstat is still over writing the local macro that I've written, but I am not sure. Any suggestions? Please give an example using code if possible as I am a novice with respect to matrix language and manipulation.
    Kind regards and thanks.

  • #2
    It seems like fitstat (SSC) is indeed overwrite the result of the model, but there is a workaround that you can save the result by using estimate restore together with local macros. Here's an example of how to combine results from logit output, estst classification (which is the new command that replaced the lstat you used) and fitstat.

    Code:
    clear*
    sysuse auto
    logit foreign price mpg headroom i.rep78
    estat classification
    estadd scalar p_corr=r(P_corr)
    est sto m1, title(Mode 1)
    fitstat
    local AIC=r(aic)
    local BIC=r(bic)
    local Nagelkerke_R2=r(r2_cu)
    est restore m1
    
    outreg2 using Table_IndependencePreferences.xls, dec(3) ///
    addstat(Log-Likelihood Full Model, e(ll),  Chi-square test, e(chi2), AIC,`AIC', BIC,`BIC', Pseudo R2, e(r2_p), Nagelkerke R2, `Nagelkerke_R2', PctCorr, e(p_corr)) ctitle("Model 1") replace

    Comment


    • #3
      Many thanks, Oded Mcdossi. For the second time you have resolved my outreg2 issue. Thanks for your helpful reply, I am all set to output my tables now and I have learned some new commands and tools that give me more flexibility in what I can add to my outreg2 outputs.

      Comment

      Working...
      X