My goal is to have Stata display (ideally, export to Latex) an M-by-N "correlation table", where however each cell is not the correlation between variables m and n, but always between the same two variables x and y where x is in categories 1...M and y is in categories 1...N. (The cells should contain the correlation coefficient and t- or p-value/significance stars.)
In the below example, I would want to investigate how the correlation between price and mpg depends varies in longer vs. shorter, and foreign vs. domestic cars. The categories M and N are not categories of x and y, but of other variables, as below:
Effectively, I need just the results from
but displayed in table form and exported.
I followed the suggestion here: https://www.statalist.org/forums/for...ed-as-a-matrix
and then outputting to excel. But this is for categories along one dimension, and I cannot figure out how this would be extended to two dimensions.
In the below example, I would want to investigate how the correlation between price and mpg depends varies in longer vs. shorter, and foreign vs. domestic cars. The categories M and N are not categories of x and y, but of other variables, as below:
Code:
set more off clear* sysuse auto gen large = 0 replace large = 1 if length > 190 sort large foreign by large foreign: pwcorr price mpg
Code:
by large foreign: pwcorr price mpg
I followed the suggestion here: https://www.statalist.org/forums/for...ed-as-a-matrix
Code:
clear* sysuse auto capture program drop mycorr program define mycorr corr price weight gen rho = r(rho) keep rep78 rho keep in 1 exit end runby mycorr, by(rep78) list, noobs clean
Comment