Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Stas Kolenikov <skolenik@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Calculation of covariance matrix for unbalanced sample? |

Date |
Thu, 3 Nov 2011 07:46:54 -0400 |

I don't think there's any. I vaguely remember a discussion some time back on the list about this. Here's the basic outline from scratch: program define pwcovmat, rclasssyntax varlistunab vars : `varlist'local p : word count `vars'tempname Covmatrix `Cov' = J(`p',`p',.)matrix rownames `Cov' = `vars'matrix colnames `Cov' = `vars'forvalues i=1/`p' { forvalues j=`i'/`p' { local x : word `i' of `vars' local y : word `j' of `vars' quietly corr `x' `y', cov matrix `Cov'[`i',`j'] = r(C) matrix `Cov'[`j',`i'] = r(C) }}return matrix Cov = `Cov'end // of pwcovmat sysuse auto corr weight price mpg, cov corr weight price mpg rep, cov pwcovmat weight price mpg rep matrix list r(Cov) On Thu, Nov 3, 2011 at 6:00 AM, <S.Jenkins@lse.ac.uk> wrote: > A colleague has data on a relatively large number of variables. His > sample is unbalanced in the sense that each variable has some missing > values. He wishes to calculate the covariance matrix for his data but > without the listwise deletion of cases that is imposed by -correlation, > covariance- or -matrix accum-. > > My first thought was that he could use -pwcorr- and loop over his > variables, and build up his matrix from the saved results. But I thought > there must be an easier or more straightforward way -- but Googling and > -findit- have not suggested any. I guess there is a relatively easy > Mata solution, but I am currently unfamiliar with that route. > > Suggestions using Stata or Mata please > > Stephen > ------------------ > Professor Stephen P. Jenkins <s.jenkins@lse.ac.uk> > Department of Social Policy and STICERD > London School of Economics and Political Science > Houghton Street, London WC2A 2AE, UK > Tel: +44(0)20 7955 6527 > Changing Fortunes: Income Mobility and Poverty Dynamics in Britain, OUP > 2011, http://ukcatalogue.oup.com/product/9780199226436.do > Survival Analysis Using Stata: > http://www.iser.essex.ac.uk/survival-analysis > Downloadable papers and software: http://ideas.repec.org/e/pje7.html > > > Please access the attached hyperlink for an important electronic communications disclaimer: http://lse.ac.uk/emailDisclaimer > > * > * 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/ > -- Stas Kolenikov, also found at http://stas.kolenikov.name Small print: I use this email account for mailing lists only. * * 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/

**Follow-Ups**:**RE: st: Calculation of covariance matrix for unbalanced sample?***From:*Nick Cox <n.j.cox@durham.ac.uk>

**References**:**st: Calculation of covariance matrix for unbalanced sample?***From:*<S.Jenkins@lse.ac.uk>

- Prev by Date:
**st: confidence intervals for predicted probabilities for different x values after probit** - Next by Date:
**RE: st: RE: RE: generate graph (try 2)** - Previous by thread:
**st: Calculation of covariance matrix for unbalanced sample?** - Next by thread:
**RE: st: Calculation of covariance matrix for unbalanced sample?** - Index(es):