# Re: st: How to stack two correlation matrix tables into one big correlation matrix (lower and upper diagonal) table?

 From Kelvin Tan To statalist@hsphsun2.harvard.edu Subject Re: st: How to stack two correlation matrix tables into one big correlation matrix (lower and upper diagonal) table? Date Wed, 17 Feb 2010 16:47:08 +1000

```Thanks Maarten and Ben,

It works very well.

Kelvin

On Mon, Feb 15, 2010 at 6:42 PM, Maarten buis <maartenbuis@yahoo.co.uk> wrote:
>
> --- On Mon, 8/2/10, Kelvin Tan asked:
>> I would like to know if I can stack two correlation matrix
>> tables into one big correlation matrix (("foreign=1") in
>> lower diagonal and (foreign=0) in upper diagonal of the
>> big correlation matrix table) .
>
> I gave a solution that worked for just the correlation
> coefficients but which could not report any stars, standard
> errors, p-values, or confidence intervals.
>
> Ben Jann just answered me privately with an example of how
> to do the latter, which I am forwarding below.
>
> Hope this helps,
> Maarten
>
>
> --- Ben Jann:
> here is some code if you just want to stack two correlation matrices:
>
> eststo clear
> sysuse auto
> local vlist price mpg weight
> foreach v of local vlist {
>    estpost correlate `v' `v' `ferest()' if foreign==0
>    foreach m in b rho p count {
>        matrix tmp = e(`m')
>        matrix coleq tmp = "foreign=0"
>        matrix `m' = tmp
>    }
>    estpost correlate `v' `v' `ferest()' if foreign==1
>    foreach m in b rho p count {
>        matrix tmp = e(`m')
>        matrix coleq tmp = "foreign=1"
>        matrix `m' = `m', tmp
>    }
>    ereturn post b
>    foreach m in rho p count {
>        quietly estadd matrix `m' = `m'
>    }
>    eststo `v'
> }
> esttab, nonumbers mtitles noobs not
>
> (Note that `ferest()' expands to the unprocessed elements of the foreach
> loop.)
>
> The lower/upper triangle thing is more difficult. Let's see ... Here's a
> solution:
>
> eststo clear
> sysuse auto
> local vlist price mpg weight
> local upper
> local lower `vlist'
> foreach v of local vlist {
>    estpost correlate `v' `lower' if foreign==1
>    foreach m in b rho p count {
>        matrix `m' = e(`m')
>    }
>    if "`upper'"!="" {
>        estpost correlate `v' `upper' if foreign==0
>        foreach m in b rho p count {
>            matrix `m' = e(`m'), `m'
>        }
>    }
>    ereturn post b
>    foreach m in rho p count {
>        quietly estadd matrix `m' = `m'
>    }
>    eststo `v'
>    local lower: list lower - v
>    local upper `upper' `v'
> }
> esttab, nonumbers mtitles noobs not
>
>
> --------------------------
> Maarten L. Buis
> Institut fuer Soziologie
> Universitaet Tuebingen
> Wilhelmstrasse 36
> 72074 Tuebingen
> Germany
>
> http://www.maartenbuis.nl
> --------------------------
>
>
>  <kelvin.tan.statalist@gmail.com> wrote:
>
>> From: Kelvin Tan <kelvin.tan.statalist@gmail.com>
>> Subject: st: How to stack two correlation matrix tables into one big correlation  matrix (lower and upper diagonal) table?
>> To: statalist@hsphsun2.harvard.edu
>> Date: Monday, 8 February, 2010, 5:12
>> Hi All,
>>
>> Having read the following post
>> http://www.stata.com/statalist/archive/2009-11/msg00012.html
>> "how to
>> produce a correlation matrix table with asterisks from
>> Stata to LaTex"
>>
>> >
>> *************
>> capt which estout
>> if _rc ssc inst estout
>>
>> sysuse auto.dta, clear
>>
>> estpost correlate trunk weight length, matrix, if
>> foreign==1
>> estpost correlate trunk weight length, matrix, if
>> foreign==0
>> esttab ., not unstack compress noobs tex
>> *************
>>
>>
>> Regards,
>> Kelvin
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/statalist/faq
>> *   http://www.ats.ucla.edu/stat/stata/
>>
>
>
>
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```