Announcement

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

  • Storing results with a large loop (>11000)

    I am trying to store results across a large loop. I have previously done as follows but am limited to the matrix size (11000).

    matrix z=J[1,6,.]
    matrix Catch=J[`n',1]

    forval i =1/`n' {
    quietly reg y x`i'
    quietly estat ic
    matrix z=r(S)
    matrix Catch(`i',1)=z[1,5]
    }

    Where `n' is a number significantly greater than >11000.

    Is there a way to store these values elsewhere or output them quickly? I know I can use the "putexcel" command but it is slow having to call the command in each loop. Are there other options?


  • #2
    You can create a new data set containing the variables i (ranging from 1 to `n') and the AIC by using -postfile-:

    Code:
    capture postutil clear
    tempfile aics
    postfile handle long n float aic using `aics'
    
    forvalues i = 1/`n' {
        quietly regress y x`i'
        quietly estat ic
        matrix z = r(S)
        post handle (`i') (z[1, 5])
    }
    postclose handle
    At the end of this code, the tempfile `aics' will have two variables: n, and aic. You can -use- it and then -save- it as a permanent file if you like, or merge it with some other data, or make it into a spreadsheet with -export excel-, or whatever else you might do with a data set.

    Do remember that whatever you want to do with temporary file `aics', you must put the code for that into your do file with the code shown above, and run it all in one fell swoop. If you just run the above code in isolation, the tempfile `aics' will disappear just after it is finally created!

    Comment


    • #3
      After a bit of struggling with exporting the tempfile, I figured it out thanks!

      Comment

      Working...
      X