[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

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

Date |
Tue, 3 Aug 2004 17:53:55 +0100 |

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. 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) * -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) Incidentally, -generate- accepts -if- conditions. Nick n.j.cox@durham.ac.uk Michael S. Hanson > I have two variables in a panel that I would like to > compute the > correlation by cross-sectional unit, then list in a compact way by > cross section. It's the listing that is the problem, as -by > id: corr x > y- yields many pages of output for my 50 cross-sections. Ideally I'd > like something similar to the output of -tabstat x y, by(id)- ... but > -tabstat- only reports univariate statistics. > > I thought this was going to be relatively easy to code, > but I ran into > one large conceptual problem: > > > decode id, gen(idstr) // string for display > egen idn = group(id) // sequential > numbers for loop > forvalues i = 1/50 { > quiet corr x y if idn == `i' > disp idstr " " `r(rho)' if idn == `i' > } > > > Namely, -display- does not accept conditions (i.e., the -if-)! > Neither, as far as I can tell, do any of the assignment > commands (e.g. > -generate-, -local-, etc.). So I've pored over the manuals hoping to > find an alternative approach, but I've come up completely empty. I'm > certain I am not thinking about the problem the "Stata way," but I > cannot seem to figure out what that way would be. I welcome any > suggestions on how to accomplish what I am looking for. TIA. > * * 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/

**Follow-Ups**:**Re: st: RE: Compact list of correlation, by cross-section***From:*"Michael S. Hanson" <mshanson@wesleyan.edu>

- Prev by Date:
**Re: st: RE: Suggestion for an added graph feature** - Next by Date:
**st: added graph feature: solution??** - Previous by thread:
**st: Compact list of correlation, by cross-section** - Next by thread:
**Re: st: RE: Compact list of correlation, by cross-section** - Index(es):

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