Announcement

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

  • Adding custom stats in a table

    Hello,

    I'm trying to create a custom table with some specific stats, namely, I want to see how many observations are missing and how many are from the a particular country. I want to do this for five variables: paddy, coffee, millet, tea and indigo. My code is as follows:

    Code:
        foreach x in paddy coffee millet tea indigo {
        count if country==74 // 74 is the relevant country code
        estadd local n_country `r(N)' 
        count if missing(`var')
        estadd local n_missing `r(N)'
                
        est store `x'
        }
                
           esttab paddy coffee millet tea indigo using "table.tex", noabbrev tex replace ///
           stats(n_country n_missing, labels("Country" "Missing")) ///
           nonote title("Study Sample Size")
    However, I get the error that "e(n_country) already defined".

    Please could someone tell me what is the issue here? Thank you!

  • #2
    estout is from SSC, as you are asked to explain in FAQ Advice #12. If you want to add stats to a group of models, you need to restore each one of them as only one can be active at a time. Currently, you are just saving the stats to the active estimates, hence the error after the second attempt.

    Code:
    foreach x in paddy coffee millet tea indigo {
        est restore `x'
        count if country==74 // 74 is the relevant country code
        estadd local n_country `r(N)'
        count if missing(`var')
        estadd local n_missing `r(N)'
    }        
    esttab paddy coffee millet tea indigo using "table.tex", noabbrev tex replace ///
    stats(n_country n_missing, labels("Country" "Missing")) ///
    nonote title("Study Sample Size")

    Comment

    Working...
    X