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

st: RE: RE: Re: ST: correlations and values


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Re: ST: correlations and values
Date   Mon, 20 Jan 2003 18:01:02 -0000

Eric Uslaner

> > I would like to create output along the lines of Fred Wolfe's fine
> > pwcorrs, but with variable labels.
> >
> > So if I have
> >
> > pwcorrs y x1 x2 x3,var(1)
> >
> > I'll get the variable names and one column of correlations
> > of x1 x2 and
> > x3 with y
> >
> > (e.g.:
> >
> > pwcorrs trust v20 v24 v26,var(1)
> >                            Pearson Correlations
> >           |    trust
> > ----------+---------
> >     trust |   1.0000
> >       v20 |   0.0110
> >       v24 |   0.3333
> >       v26 |  -0.0256
> >
> > But I'd like to have the variable labels for each variable
> > as well as
> > the names.  Tried outreg, didn't work.  Don't think that
> > Nick Winter's
> > mktab will work either from the help file.  Any ideas?

Nick Cox

> Well, I think you need to explain where the putative
> programmer is going to put those labels -- which
> could be up to 80 characters long. How much real estate
> have you got?
>

Less pessimistic approach:

1. Create a matrix of correlations, e.g.

matrixof correlate price-foreign, r(rho) matname(mycorr)

(here -matrixof- is from SSC)

2. Put the variable labels in a macro

foreach v of var price-foreign {
	local lbl : variable label `v'
	local LBL `"`LBL' "`lbl'" "'
}

3. In this case -- and in many others --
the stops (periods) will get misunderstood:

local LBL : subinstr local LBL "." "", all

4. Apply to matrix

matrix rowname mycorr = `LBL'
mat li mycorr, format(%4.3f) noheader

                             price           mpg         rep78
headroom         trunk        weight
               Price         1.000
       Mileage (mpg)        -0.456         1.000
  Repair Record 1978         0.007         0.402         1.000
       Headroom (in)         0.111        -0.400        -0.148
1.000
 Trunk space (cu ft)         0.323        -0.580        -0.157
0.661         1.000
        Weight (lbs)         0.548        -0.806        -0.400
0.479         0.669         1.000
         Length (in)         0.442        -0.804        -0.361
0.524         0.733         0.948
   Turn Circle (ft)          0.330        -0.735        -0.496
0.435         0.601         0.861
Displacement (cu in)         0.548        -0.743        -0.412
0.476         0.629         0.932
          Gear Ratio        -0.380         0.657
 0.410        -0.379        -0.511        -0.791
            Car type        -0.017         0.454
 0.592        -0.335        -0.405        -0.646

                            length          turn  displacement
gear_ratio       foreign
         Length (in)         1.000
   Turn Circle (ft)          0.863         1.000
Displacement (cu in)         0.862         0.812         1.000
          Gear Ratio        -0.723        -0.701        -0.838
1.000
            Car type        -0.611        -0.677        -0.638
0.727         1.000


It does not look too bad, done once on the _rows_...

Nick
[email protected]

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