Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: Compact list of correlation, by cross-section


From   "Michael S. Hanson" <[email protected]>
To   [email protected]
Subject   Re: st: RE: Compact list of correlation, by cross-section
Date   Tue, 3 Aug 2004 15:39:09 -0400

On Aug 3, 2004, at 12:53 PM, Nick Cox wrote:

The condition "if idn == `i'" is not only illegal,
but in any case irrelevant to the -display-.
It should just be omitted. That is, the -correlate-
command already took care of the restriction
you want, and there is only one correlation
available to display, so no ambiguity.
Unfortunately, omitting the second "if" condition does not produce what I am looking for: since there are t observations for each id, t > count(id) = 50, the first id is shown 50 times along with the (otherwise correct) correlation coefficients. Given the solutions below, I'm not going to spend more time on this now....



As it happens, there are other solutions. Here
are two:

* The -egenmore- package on SSC includes a -corr()-
function, so that I think you need something like

egen corr = corr(x y), by(id)
tabdisp id, c(corr)
This does work, although the way -tabdisp- handles missing values initially had me confused. One of the series is missing observations at the beginning of the (time series) sample, so the initial values of "corr" where missing; -tabdisp- shows these values -- as blanks. Instead,

tabdisp id if ~missing(corr), c(corr)

did the trick.



* -statsby- offers an even simpler solution,
but you lose your data. That may or may not be
what you want.

statsby "corr x y" corr=r(rho) , by(id)
Thanks, this works quite nicely! (I can always use the "saving" option and then re-use my prior datafile.)



Incidentally, -generate- accepts -if- conditions.
Yes, it certainly does. Momentary brain freeze or something. Thanks again, Nick.

-- Mike

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index