Dear all,
I have successfully generated a matrix after a tabulate command, but unsuccessfully set the right column and row names and would love a bit of help.
I found online the following strategy to name columns and rows in a matrix:
However, I have two problems with this: (1) my age variable is not labeled, and (2) decode results in an alphabetical order that does not match the results matrix order. While the matrix has the following column names after tabulating:
Using the code above leads to the following column names, which means the resulting matrix would show "JSS 1" when it should be saying "Primary 1":
To solve problem (1) I would have liked to set the rownames from a matrix already generated, something like the following:
But I failed, so simply did the following, which works well enough for my purposes:
However, I have not been able to fix problem (2). I have played with defining the local myself, but I also failed at that:
Any ideas on how to do this without having to manually add the column names?
I am using Stata 13 by the way.
Thank you all very much!
I have successfully generated a matrix after a tabulate command, but unsuccessfully set the right column and row names and would love a bit of help.
I found online the following strategy to name columns and rows in a matrix:
Code:
tab age Grade if Enrolled==1 & inrange(age,5,35) [iw=wt_hh], matcell(T1) decode age, gen(age_s) levelsof age_s, local(agelabels) matrownames T1 = `agelabels' decode Grade, generate(Grade_s) levelsof Grade_s, local(Gradelabels) mat colnames T1 = `Gradelabels'
Code:
"Primary 1" "Primary 2" "Primary 3" "Primary 4" "Primary 5" "Primary 6" "JSS 1" "JSS 2" "JSS 3" "SSS 1" "SSS 2" "SSS 3" "SSS 4"
Code:
"JSS 1" "JSS 2" "JSS 3" "Primary 1" "Primary 2" "Primary 3" "Primary 4" "Primary 5" "Primary 6" "SSS 1" "SSS 2" "SSS 3" "SSS 4"'
Code:
tab age Grade if Enrolled==1 & inrange(age,5,35) [iw=wt_hh], matcell(T1) matrow(rows) mat T1 = T1 mat rownames T1 = `rows'
Code:
tab age Grade if Enrolled==1 & inrange(age,5,35) [iw=wt_hh], matcell(T1) matrow(rows) mat T1 = rows, T1
Code:
local labels "" levelsof Grade, local(dvs) foreach level in `dvs' { local varlabelname: value label Grade local varName: label `varlabelname' `level' local labels "`labels'" " " "`varName'" } di "`labels'"
I am using Stata 13 by the way.
Thank you all very much!
Comment