Announcement

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

  • AIC and BIC for a model with GS2SLS

    Hello everyone,

    In a model estimated using this line of code:

    xi: spregress Unemployment Education Young Manufacturing Services Density ActivityRate i.CNTR_CODE, gs2sls dvarlag(Wme)

    I'm not able to apply the command "estat ic". I really need the AIC and BIC, so if you know how I can do that using stata, please help me. In case I'll have to do it manually, I'd still need some guidance. Thank you in advance.

  • #2
    You'd need to use the ml option to get the LL. (and estat ic would work)

    Comment


    • #3
      This might work (this is AIC and BIC formula)

      Code:
      sysuse auto, clear
      
      egen id = group(make)
      spset id 
      
      reg price mpg 
      estat ic
      local ll = -(e(N)/2)*ln(e(rss)) - (e(N)/2)*ln(2*_pi/e(N)) - (e(N)/2)
      di e(ll) _col(20) `ll'
      di "AIC = " %5.1f -2*`ll' + 2*(e(df_m)+1)
      di "BIC = " %5.1f -2*`ll' + (e(df_m)+1)*ln(e(N))
      
      di "AIC = " %5.1f -2*`e(ll)' + 2*(e(df_m)+1)
      di "BIC = " %5.1f -2*`e(ll)' + (e(df_m)+1)*ln(e(N))
      
      spregress price mpg , ml
      estat ic
      
      spregress price mpg , gs2sls
      predict e, resid
      g e2 = e^2
      summ e2
      local ll = -(e(N)/2)*ln(`r(sum)') - (e(N)/2)*ln(2*_pi/e(N)) - (e(N)/2)
      di "AIC = " %5.1f -2*`ll' + 2*(e(df_m)+1)
      di "BIC = " %5.1f -2*`ll' + (e(df_m)+1)*ln(e(N))
      Last edited by George Ford; 26 Feb 2024, 13:46.

      Comment


      • #4
        Thank you really much George. Can you please give me also the BIC codes? I want to say that I only used the part of your code starting from the line "spregress price mpg, gs2sls", because it's the same estimator I'm using.
        Thanks to your code, I've been able to calculate the AIC of the gs2sls model and the result is -595,89838. If I apply the command "estat ic" to the same dataset but with the ml estimator, I obtain these results:

        Click image for larger version

Name:	image_33925.png
Views:	1
Size:	65.5 KB
ID:	1744666


        So, the AIC is pretty far from this one, I was expecting a positive value maybe lower than 1270. But I noticed that the value I calculated is pretty close to this "ll(model)" value, which I'm not really familiar to what it means. I'd like to ask you if I did something wrong or if I'm missing something and maybe I can obtain a positive value to compare to 1270.419. You'll be really helpful to my cause if you answer these questions. Thank you anyway for the help.

        Comment


        • #5
          Code for BIC provided in latest post (I updated it). The first post was the LL.
          Here it is again.

          Code:
           sysuse auto,
          clear  egen id = group(make)
          spset id  
          reg price mpg  
          estat ic
          local ll = -(e(N)/2)*ln(e(rss)) - (e(N)/2)*ln(2*_pi/e(N)) - (e(N)/2)
          di e(ll) _col(20) `ll' di "AIC = " %5.1f -2*`ll' + 2*(e(df_m)+1)
          di "BIC = " %5.1f -2*`ll' + (e(df_m)+1)*ln(e(N))  
          di "AIC = " %5.1f -2*`e(ll)' + 2*(e(df_m)+1)
          di "BIC = " %5.1f -2*`e(ll)' + (e(df_m)+1)*ln(e(N))  
          spregress price mpg , ml
          estat ic  
          spregress price mpg , gs2sls
          predict e, resid
          g e2 = e^2
          summ e2
          local ll = -(e(N)/2)*ln(`r(sum)') - (e(N)/2)*ln(2*_pi/e(N)) - (e(N)/2)
          di "AIC = " %5.1f -2*`ll' + 2*(e(df_m)+1)
          di "BIC = " %5.1f -2*`ll' + (e(df_m)+1)*ln(e(N))

          Comment

          Working...
          X