Hi all,
I am attempting to create a series of matrices with row and column names, with the ultimate goal of exporting these matrices to excel. I am using Stata 15.1 on Windows 7. I used this post as a guide, but am encountering issues when it comes to applying names to the matrix. https://www.statalist.org/forums/for...d-column-names. An example of my process is below:
The problem is that I receive the error message " matrix rownames percent = `divisionvl' conformability error r(503); " From reading the previous Stata list post that I reference above, I think I could understand how this error might arise if there were missing values for the data I wanted to use. However, that's not the case here- neither variable in this example has any missing values.Does anyone have any insight on how I can avoid this error in this example, and potentially with data that does contain missing values? Thanks!
I am attempting to create a series of matrices with row and column names, with the ultimate goal of exporting these matrices to excel. I am using Stata 15.1 on Windows 7. I used this post as a guide, but am encountering issues when it comes to applying names to the matrix. https://www.statalist.org/forums/for...d-column-names. An example of my process is below:
Code:
clear set more off *----- example data ----- webuse citytemp2 mdesc // note no missing data for the two variables drop if missing(division) drop if missing( agecat ) tab division agecat, missing matcell (freq) matrix list freq matsum freq, column(columntotal) //create matrix with each cell as a percent of the columntotal mata : st_matrix("percent", st_matrix("freq") :/st_matrix("columntotal")) matrix list percent *----- levels only ----- levelsof division, missing local(down) levelsof agecat, missing local(across) matrix rownames percent = `down' matrix colnames percent = `across' *----- labels too ----- foreach var of varlist division agecat { // retrieve levels of each variable levelsof `var', local(`var'_levels) // create local with all corresponding value labels foreach val of local `var'_levels { local `var'vl ``var'vl' `"`: label (`var') `val''"' } } //apply value labels as matrix row and column names matrix rownames percent = `divisionvl' matrix colnames percent = `agecatvl' matrix list percent
The problem is that I receive the error message " matrix rownames percent = `divisionvl' conformability error r(503); " From reading the previous Stata list post that I reference above, I think I could understand how this error might arise if there were missing values for the data I wanted to use. However, that's not the case here- neither variable in this example has any missing values.Does anyone have any insight on how I can avoid this error in this example, and potentially with data that does contain missing values? Thanks!
Comment