Announcement

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

  • Storing standard errors in matrix

    Hi everyone. I am looking to store iterative sets of standard errors in a matrix for a Monte Carlo Simulation. The problem I'm having is that I'm not sure where to put the matrix, and if there is specific syntax for the standard error matrix. I need the standard errors store in a matrix so I can perform some calculations for my econometrics assignment. Appreciate any help! Also, not sure if these code delimiters worked, I'm still trying to figure that out.
    Code:
    clear
    
    local mc = 1000
    set seed 368
    set obs `mc'
    gen data_n = .
    gen data_store_x = .
    gen data_store_cons = .
    
    mata: beta_10 = J(1000,1,.)
    mata: beta_100 = J(1000,1,.)
    mata: beta_1000 = J(1000,1,.)
    mata: beta_10000 = J(1000,1,.)
    foreach n of numlist 10 100 1000 10000 {
        quietly {
            forvalues i = 1(1) `mc' {
                if floor((`i'-1)/100) == (`i' -1)/100 {
                    noisily display "Working on `i' out of `mc' at $S_TIME"
                }
                preserve
    
                clear
    
              set obs `n'
    
                gen x = rnormal() *3 + 6
    
                gen e = rnormal() - 0.5
    
                gen y = 3 + 4*x + e
                
                reg y x, vce(robust)
    
                local xcoef = _b[x]
                local const = _b[_cons]
                mata: beta_`n'[`i',1] = `xcoef'
                restore
            
                
                replace data_n = `n' in `i'
                replace data_store_x = `xcoef' in `i'
                replace data_store_cons = `const' in `i'
                    }
            }
        summ  data_n data_store_x data_store_cons, detail
        
    }
Working...
X