Dear Readers (struggling with "collect")
Its been a long time, so please excuse rough code.
I want a table of descriptives with mean and sd stacked and columns for different data sets (of the same or equivalent) variables. I then want to add a column for correlation coefficients between the equivalent variables in the different data sets.
I compute dtable for each of the data sets, and combine them.
Thanks
Richard
Its been a long time, so please excuse rough code.
I want a table of descriptives with mean and sd stacked and columns for different data sets (of the same or equivalent) variables. I then want to add a column for correlation coefficients between the equivalent variables in the different data sets.
I compute dtable for each of the data sets, and combine them.
Code:
//correlation matrix
mat list M
matrix input M = (1, -.46, .28, -.04 \ -.46, 1, -.06, .17 \ .28, -.06, 1, -.50 \ -.04, .17, -.50, 1)
corr2data var1 var2 var1_1 var2_1, n(100) corr(M) cstorage(full) means(.77, .08, .75, .07) clear
corr *
su *
collect clear
qui dtable var1 var2, nformat(%5.2f mean sd) name(set1) replace
qui dtable var1_1 var2_1, nformat(%5.2f mean sd) name(set2) replace
collect combine both = set1 set2
collect layout (var#result) (collection)
// not what I want
collect recode var var1_1 = var1
collect recode var var2_1 = var2
collect style header result, level(hide)
*collect style autolevels var var1 var2 var3 var6 _N, clear
collect layout (var#result[frequency mean sd]) (collection)
collect preview
// now add a column for correlation coefficients between var1-4
collect create rho, replace
collect set rho
local dim 4
matrix C = J(`dim',1,.)
foreach i in 1 2 {
* compute correlation
correlate var`i' var`i'_1
* collect result and tag it for easy arrangement/layout
collect get rho = (r(rho)) , tags(Y[var`i'] X[var])
}
collect style cell result[rho], nformat(%9.3f)
collect layout (Y) (X) (result[rho])
// now I want to add the column of correlation coefficients (X) to both variables and
// output a table such as
/*
set1 set2 corr(set1/2)
N 100 100 100
var1 mean 0.77 0.75 0.28
sd (1) (1)
var2 mean 0.08 0.7 0.17
sd (1) (1)
*/
Richard

Comment