Hi everyone,
I am trying to create a STATA command for econometric analysis, in which there is a command that involves creating data columns that are eigenvectors derived from a spatial connection matrix.
When I test with real data, my commands work. But when I try to program them into a command, it gives an error.
The code and results are attached at the end of the post.
I have tried to find the logic error and read the documentation on matrices and programming in STATA but have not been able to fix the error. I hope to receive help from experts in STATA and mata.
Thanks in advance.
When I test with real data, my commands work:
When I try to program them into a command, it gives an error:
I am trying to create a STATA command for econometric analysis, in which there is a command that involves creating data columns that are eigenvectors derived from a spatial connection matrix.
When I test with real data, my commands work. But when I try to program them into a command, it gives an error.
The code and results are attached at the end of the post.
I have tried to find the logic error and read the documentation on matrices and programming in STATA but have not been able to fix the error. I hope to receive help from experts in STATA and mata.
Thanks in advance.
When I test with real data, my commands work:
Code:
* Generate data for W matrix clear all qui { // Open qui input v1 v2 v3 v4 0 0.1 0.3 0.2 0.1 0 0.2 0.3 0.3 0.2 0 0.2 0.2 0.3 0.2 0 end spmat dta W v1-v4, replace * Generate eigenvectors from spmat W matrix spmat getmatrix W w_m mata: E_values = . E_vectors = . symeigensystem(w_m, E_vectors, E_values) st_matrix("E_m", E_vectors) end svmat E_m, names(E) } // Close qui sum E* clear all
Code:
. * Generate data for W matrix . clear all . qui { // Open qui . . sum E* Variable | Obs Mean Std. dev. Min Max -------------+--------------------------------------------------------- E1 | 4 -.4993792 .0287599 -.5242861 -.4744724 E2 | 4 0 .5773502 -.6015009 .6015009 E3 | 4 0 .5773502 -.6015009 .6015009 E4 | 4 .0249068 .5766335 -.4744724 .5242861 . clear all
Code:
* Programing cap program drop eigvecvars program define eigvecvars version 11 syntax varlist, Wmatrix(name) * Check spmat qui cap spmat summarize `wmatrix' if _rc > 0 { di as err "spmat object `wmatrix' not found" exit 498 } spmat getmatrix `wmatrix' w_m mata: E_values = . E_vectors = . symeigensystem(w_m, E_vectors, E_values) st_matrix("E_m", E_vectors) end svmat E_m, names(E) end
Code:
. do "C:\Users\lnd9492\AppData\Local\Temp\STD21b4_00001a.tmp" . cap program drop eigvecvars . program define eigvecvars 1. version 11 2. syntax varlist, Wmatrix(name) 3. . * Check spmat . qui cap spmat summarize `wmatrix' 4. if _rc > 0 { 5. di as err "spmat object `wmatrix' not found" 6. exit 498 7. } 8. . spmat getmatrix `wmatrix' w_m 9. mata: 10. E_values = . 11. E_vectors = . 12. symeigensystem(w_m, E_vectors, E_values) 13. st_matrix("E_m", E_vectors) 14. end . svmat E_m, names(E) matrix E_m not found r(111);
Comment