I am using stata 16.1 and am struggling with the following challenges:
1.) I want to compare two identical lists of variables by looping the test. Afterwards I want only display the unique combinations, please see the "Summary t-test" table at the end of my code. If varlist = A B C I want only display do the comparison for AA AB AC (BA) BB BC (CA CB) CC, combinations in brackets should not be performed/displayed.
2.) In the summary tabel I want to replace the _ with spaces for the row names. And - if possible - use variable labels instead of variable names.
Her is an example:
Code:
sysuse auto
// Input of all variables that are to be compared
local varlist1 price headroom gear_ratio
// Matrix for t-test
local nvarlist1 : word count `varlist1'
matrix t_test = J((`nvarlist1'*`nvarlist1'),1,.)
//labeling of columns
matrix colnames t_test = p-value
local row = 1
foreach var1 in `varlist1' {
foreach var2 in `varlist1' {
ttest `var1' == `var2'
matrix t_test[`row', 1] = r(p)
//labeling rows by preparing macro - how do I remove the underscores before and after vs?
//matrix rownames t_test "`var1' vs `var2'"
local lable_rownames_ttest `lable_rownames_ttest' "`var1'_VS_`var2'"
local ++row
}
}
//labeling rows
matrix rownames t_test = `lable_rownames_ttest'
// final output
matlist t_test, format(%7.6f) twidth(30) title(Summary t-test)
0 Response to Display only unique/destinct combinations in looped test of two identical varlists
Post a Comment