Hello, everyone. I am trying to create survey data statistics using matrix and export the statistics to tex file by frmttable (many variables in one table). Sometimes, it works. But there are some exceptions. For example, the variable "importance1" has value scaled from 1 to 5 (i.e., the survey participant evaluated the survey question from 1 to 5). The variable "importance2" has also value scaled from 1 to 5. However, the value 4 is missing in this variable "importance2", simply because no one indicated 4 in this survey question. When I append the matrix, it shows the conformability error, because the number of columns does not match anymore.
What I can do is to create another matrix manually. However, as I have many variables for such a case, it would be super helpful if anyone has a better solution to automate this step. Basically, it should automatically create 0 in that column for any variables, which have missing numbers in the scale 1 - 5. Any ideas?
Thank you very much.

Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(id importance1 importance2) 1 1 1 2 1 1 3 5 1 4 5 4 5 4 5 6 4 3 7 3 5 8 5 4 9 2 4 10 2 3 end
Code:
tab importance1 tab importance2 mata: mata clear local i = 0 foreach var1 in importance1 importance2 { g var1`i' = `var1' estpost tabulate var1`i', missing mat percent`i' = e(pct) mat list percent`i' local ++i } mat define percent_all = (percent0 \ percent1) mat list percent_all
What I can do is to create another matrix manually. However, as I have many variables for such a case, it would be super helpful if anyone has a better solution to automate this step. Basically, it should automatically create 0 in that column for any variables, which have missing numbers in the scale 1 - 5. Any ideas?
Thank you very much.
Code:
mata: mata clear local i = 0 foreach var1 in importance1 { g var1`i' = `var1' estpost tabulate var1`i', missing mat percent`i' = e(pct) mat list percent`i' local ++i } tab importance2, missing mat define percent1 = (30.00,0.00,20.00,30.00,20.00,100.00) mat define percent_all = (percent0 \ percent1) mat list percent_all * Generate output table saved as tex file. frmttable using "${tables}/texfiles/table_ex.tex", tex statmat(percent_all) sdec(2) /// ctitles("", "1", "2", "3", "4", "5", "Overall") /// rtitles("Importance 1" \ "Importance 2") /// replace
Comment