Announcement

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

  • Looping correlation between variables

    Hi,
    With following data:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(disease_experience drought_experience flood_experience disease_prediction drought_prediction flood_prediction)
    1 3 1 2 1 3
    2 4 3 3 3 4
    3 5 4 4 6 5
    4 6 5 1 7 6
    end
    I executed
    Code:
    unab experience : *_experience
    local experience: subinstr local experience "_experience" "", all
    
    unab prediction : *prediction
    local prediction : subinstr local prediction "_prediction" "", all
    
    local prefixes : list experience & prediction
    
    foreach s of local prefixes { 
    pwcorr `s'_experience `s'_prediction, sig
    }
    Actually, I wanted a single matrix of all the coefficients and p values with *experience variables on row and *prediction variables on column. But, it produces as many matrices as the number of variables.

    Would any tweaking in the code help me get what I wanted?

  • #2
    Code:
    ssc describe cpcorr
    ssc install cpcorr
    help cpcorr
    P-values need more work. But you can look over the resulting matrix: the degrees of freedom are a constant for all cells.
    Last edited by Nick Cox; 09 May 2019, 06:52.

    Comment


    • #3
      Thanks. Much appreciated.

      Comment


      • #4
        Hi,
        Could we incorporate star (0.05) thing (i.e. to indicate if the correlation is significant) into the cpcorr syntax?
        Thanks

        Comment


        • #5
          Who is we here?

          I can only speak for myself as author of this command: I don't know how that could be done without complete rewriting of the command and I have no interest in doing it myself. Sorry if that is disappointing.

          Feel free to clone the command under a different name with whatever acknowledgment fits the case.

          Comment

          Working...
          X