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

From |
"Michael S. Hanson" <mshanson@wesleyan.edu> |

To |
statalist@hsphsun2.harvard.edu |

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

Date |
Tue, 3 Aug 2004 12:39:06 -0400 |

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.

-- 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/

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

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