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

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

From   "Nick Cox" <[email protected]>
To   <[email protected]>
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. 

[email protected] 

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:

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