Hi there,
I am using Stata 16 and am ultimately trying to create a table that shows the % of e.g. males/female, different age categories etc. that are an insomnia case (insomniacase is a binary yes/no variable).
I can get the data I need using the following code:
However, I would then have to copy & paste each individual number from the Stata output into a word table which my supervisor doesn't want me to do as I actually have 30 variables(all binary/categorical) and am likely to have to repeat this analysis numerous times in different iterations.
He has suggested I use the tabstat command as follows:
(FYI we have included semean here as we will use this in some plots later on).
However, this gives me the data I need in a single column (8x1) and without row names (the name of each age category), when what I actually want is to have a matrix in the same format as the tabstat output (4 x 2) with the names of the different categories). How can I do this? I have tried transposing the matrix (e.g. mat A= A') but that just puts the data into one row rather than one column....
Once I've got my matrix for one variable in the right format I'll need to repeat this so that I have a matrix for each of my variables. Is there then a way to then combine all of my matrices and then export the final big matrices into excel or word?
I am new to Stata and have never used tabstat or matrices before so any help gratefully received!
Many thanks,
Mel
I am using Stata 16 and am ultimately trying to create a table that shows the % of e.g. males/female, different age categories etc. that are an insomnia case (insomniacase is a binary yes/no variable).
I can get the data I need using the following code:
Code:
foreach varname of varlist sex age_cat ethnicity { tab `varname' insomniacase, row nofreq }
He has suggested I use the tabstat command as follows:
Code:
tabstat insomniacase, by(age_cat) stats(mean semean) save return list matrix A= r(Stat1) \ r(Stat2) \ r(Stat3) \ r(Stat4) svmat A
However, this gives me the data I need in a single column (8x1) and without row names (the name of each age category), when what I actually want is to have a matrix in the same format as the tabstat output (4 x 2) with the names of the different categories). How can I do this? I have tried transposing the matrix (e.g. mat A= A') but that just puts the data into one row rather than one column....
Once I've got my matrix for one variable in the right format I'll need to repeat this so that I have a matrix for each of my variables. Is there then a way to then combine all of my matrices and then export the final big matrices into excel or word?
I am new to Stata and have never used tabstat or matrices before so any help gratefully received!
Many thanks,
Mel
Comment