I'd like to verify that the matrix code below does what it's supposed to be doing.
Its purpose is to store p values from the polychoric correlation command run for every combination of two vars in a varlist.
I created it based on the code here:
https://www.statalist.org/forums/for...n-table-matrix
But it looks like some lines there use syntax that doesn't work for my dataset. For instance, this throws an error in my code:
Not sure why.
My modified code below appears to work, judging from the final result. However, I thought that the matrix would be empty on one side of the diagonal but it isn't, which puzzles me. Also thank you to Maarten Buis for the earlier code!
Chris
Its purpose is to store p values from the polychoric correlation command run for every combination of two vars in a varlist.
I created it based on the code here:
https://www.statalist.org/forums/for...n-table-matrix
But it looks like some lines there use syntax that doesn't work for my dataset. For instance, this throws an error in my code:
Code:
matrix p = J(`l',1,.)
My modified code below appears to work, judging from the final result. However, I thought that the matrix would be empty on one side of the diagonal but it isn't, which puzzles me. Also thank you to Maarten Buis for the earlier code!
Chris
Code:
// store the unabbreviated varlist in the local macro y // you can use that to name the rows in your matrix unab y : ausa aeurop crisk cpossi dsever dmeasl eclass eairpl kvacget kvacpay // prepare an empty matrix in which to store the // p-values matrix p = J(10, 10, .) matrix rownames p = `y' matrix colnames p = "p" // look at the empty matrix matlist p // loop over the variables and store the p-values local a = 1 local b = 1 foreach x1 of local y { foreach x2 of local y { polychoric `x1' `x2' matrix p[`a',`b'] = r(pLR0) local ++a } local a = 1 local ++b } // admire the result matlist p
Comment