Dear all,
I came across a relativley simple problem that, so far, I have been unable to solve on my own. The basic issue is the following: I have generated some datasets in MatLab (saved as .txt-files) that I want to import into Mata after loading them as datasets into Stata.
For the purpose of exposition I have created the following minimal working example (MWE): Say I want to generate two datasets which will be exported and saved as .txt-files. In the following, these datasets shall be loaded into Mata from Stata such that I can process the matrices (in the MWE this is extracting vecotrs) in Mata. Unfortunately, my code does not work:.
I don't quite understand why Mata can't find the vars matrix. However, replacing the Mata loop by the following expression gives the desired result (but is unfortunately no solution to my actual problem that is not contained in the MWE):
Since I reckon that the solution to this problem must be rather obivous, I very much appreciate any kind of help or comments.
Thanks in advance,
Toby
I came across a relativley simple problem that, so far, I have been unable to solve on my own. The basic issue is the following: I have generated some datasets in MatLab (saved as .txt-files) that I want to import into Mata after loading them as datasets into Stata.
For the purpose of exposition I have created the following minimal working example (MWE): Say I want to generate two datasets which will be exported and saved as .txt-files. In the following, these datasets shall be loaded into Mata from Stata such that I can process the matrices (in the MWE this is extracting vecotrs) in Mata. Unfortunately, my code does not work:.
Code:
clear set more off /* Generating these two data sets is needed for exposition and reproduction only */ forvalue i = 1/2 { set obs 20 set seed `i' gen v1 = runiform() gen v2 = runiform() export delimited using result_`i'.txt, novar replace capture clear } /* Mata */ mata mata clear for (i=1; i<=2; i++) { stata("capture clear") stata(sprintf("import delimited result_%f.txt", i)) stata("putmata vars = (v1 v2), replace") V1 = vars[|1,1 \ 20, 1|] /* this is where Stata reports the error message: <istmt>: 3499 vars not found r(3499); /* } end
Code:
for (i=1; i<=2; i++) { stata("capture clear") stata(sprintf("import delimited result_%f.txt", i)) stata("putmata vars = (v1 v2), replace") stata("mata: V1 = vars[|1,1 \ 20, 1|]") stata("mata: V2 = vars[|1,2 \ 20, 2|]") }
Thanks in advance,
Toby
Comment