I've created a matrix of Halton Draws in Mata, and I'd like to use each column of the matrix as a variable in Stata. Here's some code that works and shows what I'm trying to do:
However, the getmata command does not work in .ado files, which is where I want it to go. So I need a way to do the same thing, but without getmata. Here's where I've got so far:
However, even after reading the documentation, I can't figure out a way to get that penultimate line to loop over f1_1, f1_2 ... etc. I tried this:
But it doesn't work. Any ideas?
Code:
clear set obs 100 local nsimulations 100 local N = _N mata hdrawsburn = J(`N'+10,100,.) hdraws = J(`N',100,.) p = (3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547) for (i=1; i<=100; i++) { hdrawsburn[,i] = ghalton(`N'+10,p[1,i],0) } for (i=1; i<=`N'; i++) { hdraws[i,] = hdrawsburn[i+10,] } hdraws = hdraws' end getmata (f1_*)=hdraws
Code:
clear set obs 100 local nsimulations 100 local N = _N forval i = 1/`nsimulations'{ gen double f1_`i' = . } mata hdrawsburn = J(`N'+10,100,.) hdraws = J(`N',100,.) p = (3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547) for (i=1; i<=100; i++) { hdrawsburn[,i] = ghalton(`N'+10,p[1,i],0) } for (i=1; i<=`N'; i++) { hdraws[i,] = hdrawsburn[i+10,] } hdraws = hdraws' st_store(.,"f1_1",hdraws[,1]) end
Code:
for (i=1; i<=`N'; i++) { st_store(.,"f1_i",hdraws[,i]) }
Comment