Hello,

I need to run correlations between variables - for simplicity let's say only between two variables X and Y - by company (I have around 200 companies).
I would like to export just the correlation the two variables (without the 1s) in a separate row for each company, and include the number of obs used and the company name.
Also, if there are no observations, I would like to keep the row with the label so that I know which companies don't have enough obs.

I've tried this, among other things, but cannot make it vertical (row by row) and I cannot add firm names, and for the missing ones I just get an error and the program stops.


foreach i in 111 112 122 124 {
eststo: estpost corr X Y if firm==`i'
}
esttab using "Table2_Corr15.csv", wide not nonumber nonotes b(%3.2f) nolines obslast label compress


Thanks a lot!