Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Egen and Gen with Pcorr

    Hi Statalisters,

    I am attempting to create a variable equal to the partial correlation between an IV and a DV, stratified on a categorical variable.

    For models with a single IV, this has proven quite simple:
    sysuse auto
    egen PMcorr=corr(mpg price), by(foreign)
    ta PMcorr


    However, it has proven problematic to replicate this procedure with additional IVs.
    The model I wish to create is functionally similar to:

    sysuse auto
    ta rep78, gen(rep_)
    by foreign: pcorr mpg price rep_*

    in that it is stratified by a categorical variable, has multiple IVs, and contains both continuous and categorical IVs. I wish to generate from this a variable equal to the partial correlation between price and mpg. Is this possible? The limited documentation on pcorr did seem promising.

    Thanks in advance,

    Nick

  • #2
    corr() as a egen function will, I believe, work only if you download egenmore from SSC, as you are asked to explain.

    I don't know of an equivalent function for partial correlation. It wouldn't seem a good idea to me to try to write a general egen function. I don't know what use a variable containing partial correlations might be, but using statsby to create a reduced dataset with partial correlations and then combining with the original dataset via a merge would seem one way forward.

    Comment

    Working...
    X