Announcement

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

  • Save specific output from multiple regressions

    Dear all,

    I am new to Stata and apologies if I post something in a wrong way.

    I want to run many ARMA(p,q) models for p,q=0,1,3 and I want to gather together in one table the AIC and BIC values for all the combinations of the (p,q) values.

    What I know so far is that to get the AIC and BIC for the ARMA(0,0) I type in
    arima var, arima(0, 0, 0)
    estat ic

    But since I have many different ARMA(p,q) models is there a way to get the desired output on AIC/BIC in one table without seaching eah output separately?


    I assume that the variables are stationary, so d=0 in ARIMA(p,d,q).

    Best,
    John
    Stata 14SE
    Windows 10

  • #2
    Welcome to the list! Here's some working code that I hope will get you started. I haven't fitted time series models since I was at university 30 years ago, so I took the example from the help file.

    There are a lot of concepts for a new Stata user. For most of them it should be obvious where to look in the help (e.g., postfile, foreach).

    A concept that is not so obvious is how Stata stores the results of calculations. Look in the help for -return-. The results from -estat- are stored in a 1 x 6 matrix where the 5th element is the AIC and the 6th the BIC. I write these to local macro variables.

    If you type "ereturn list" after fitting the ARMA model you will see a list of stored results. If you want to save additional quantities then they can easily be added to the postfile.

    Code:
    version 14
    tempname memhold
    tempfile results
    
    webuse wpi1
    postfile `memhold' ar ma aic bic using `results', replace
    forvalues ar = 0/2 {
    forvalues ma = 0/2 {
          quietly arima wpi, arima(`ar',0,`ma')
          quietly estat ic
          local aic = r(S)[1,5]
          local bic = r(S)[1,6]
          post `memhold' (`ar') (`ma') (`aic') (`bic')
    } 
    }
    postclose `memhold'
    use `results'
    list
    Here is the output.

    Code:
    . list
    
         +-------------------------------+
         | ar   ma        aic        bic |
         |-------------------------------|
      1. |  0    0   1200.395   1206.036 |
      2. |  0    1   1039.044   1047.505 |
      3. |  0    2   885.7755   894.2363 |
      4. |  1    0   409.8548   418.3156 |
      5. |  1    1   353.2209   364.5021 |
         |-------------------------------|
      6. |  1    2   335.7601   349.8615 |
      7. |  2    0   305.1458   316.4269 |
      8. |  2    1   294.7223   308.8237 |
      9. |  2    2   295.7058   312.6275 |
         +-------------------------------+

    Comment


    • #3
      please i am a new bee in stata and i really love how it works but right now i am faced with some challenges. i am working with sex as a categorical variable and i have successfully converted it using the code 'encode sex' but now i want to obtain the observation, mean and standard deviation of only the male sample. please what do i need to do? this is really pressing

      Comment


      • #4

        furthermore i need help on how to obtain this file from my stata 14 software. sysuse auto.dta
        (what i get in trying to obtain it is
        'no; data in memory would be lost
        r(4);'

        Comment


        • #5
          There's a simpler solution to your specific question, than that I first posted.

          Code:
          version 14
          webuse wpi1
          forvalues ar = 0/2 {
          forvalues ma = 0/2 {
                quietly arima wpi, arima(`ar',0,`ma')
                estimates store arma`ar'`ma'
          } 
          }
          estimates stats arma??
          Results are as follows:

          Code:
          . estimates stats arma??
          
          Akaike's information criterion and Bayesian information criterion
          
          -----------------------------------------------------------------------------
                 Model |          N   ll(null)  ll(model)      df        AIC        BIC
          -------------+---------------------------------------------------------------
                arma00 |        124          .  -598.1975       2   1200.395   1206.036
                arma01 |        124          .  -516.5222       3   1039.044   1047.505
                arma02 |        124          .  -439.8878       3   885.7755   894.2364
                arma10 |        124          .  -201.9274       3   409.8548   418.3156
                arma11 |        124          .  -172.6105       4   353.2209   364.5021
                arma12 |        124          .  -162.8801       5   335.7601   349.8615
                arma20 |        124          .  -148.5729       4   305.1458   316.4269
                arma21 |        124          .  -142.3611       5   294.7223   308.8237
                arma22 |        124          .  -141.8529       6   295.7058   312.6275
          -----------------------------------------------------------------------------
          Note: BIC uses N = number of observations. See [R] BIC note.
          Using postfile is more general. The postfile code can be simplified.

          Code:
          version 14
          tempname memhold
          tempfile results
          
          webuse wpi1
          postfile `memhold' ar ma aic bic using `results', replace
          forvalues ar = 0/2 {
          forvalues ma = 0/2 {
                quietly arima wpi, arima(`ar',0,`ma')
                quietly estat ic
                post `memhold' (`ar') (`ma') (r(S)[1,5]) (r(S)[1,6])
          } 
          }
          postclose `memhold'
          use `results'
          list

          Comment


          • #6
            Thank you so much all of you. Perfect!!

            Comment

            Working...
            X