Announcement

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

  • Retreiving AIC value after estat ic

    Hi all,

    I'd like to save the AIC values of a number of models in a dataset. I have the following code below. But I am not actually getting the AIC value like this, the local remains empty... Can anyone help?

    Thanks!

    Sandra

    foreach var of varlist rural_wb-bcg{
    use prev_allcov_4model, clear
    quietly xtmelogit bc `var' || iso3: , binomial(n) or
    estat ic
    regsave using xtmelogit_`var', replace
    use xtmelogit_`var', clear
    local aic=s[1,6]
    gen aic=`aic'
    gen model="`var'"
    save xtmelogit_`var', replace
    use prev_allcov_4model, clear
    }

  • #2
    -regsave- is a user-written package from ssc, not a built-in feature of Stata.

    Its help file indicates that it "fetches output from Stata's e() macros, scalars, and matrices and stores them in a Stata-formatted dataset." The AIC value from -estat ic- is returned in r(), not e(), so your -regsave- would not have stored it. Also, -estat- does not creat a matrix named "s" as your code assumes, but rather returns one in r(S). You can access elements of r(S) by assigning it a matrix s = r(S), and then referencing them, as you do, as s[1,6]

    All this being said, I would use the built-in command -postfile- for your purposes.

    Regards, Mike



    Comment


    • #3
      Thanks Mike! Also I had estat in the wrong place. Just in case it is useful for others, this code works

      foreach x in `vars' {
      use prev_allcov_4model, clear
      xtmelogit bc `x' || iso3: , binomial(n) or
      regsave using xtmelogit_`x', replace
      use xtmelogit_`x', clear
      estat ic
      mat s=r(S)
      local aic=s[1,6]
      gen aic=`aic'
      gen model="`x'"
      save xtmelogit_`x', replace
      use prev_allcov_4model, clear
      }

      Comment


      • #4
        A bit late to the party, but just to clarify, for anyone referring to this problem -s[1,6] accesses the Bayesian Information Criteria entry and not the AIC, this would be s[1,5]

        Best,
        Rhys

        Comment

        Working...
        X