Announcement

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

  • Making graph from loose coordinates of correlation matrix

    Dear stata-users,

    Could someone please help me with the following: I have a variable called hlthlog and I create the lag of hlthlog for 15 values (so 15 lags in total). For each lag, I would like to calculate the correlation between this variable and hlthlog. That is (the lower left element of the correlation matrix). Now I would like to store each of these correlations and plot them in a graph to see how the correlation changes as I increase the lag. My code so far is below but I have no idea how to continue.

    Any suggestions would be greatly appreciated.

    Best,

    Floor


    Code:
    gen hlthabs = abs(hlthlog)
    forvalues i= 1 / 15 {
        gen hlthlog`i' = abs(hlthlog[_n+`i'])
        corr hlthlog`i' hlthabs 
    }



    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float hlthlog
       .009653257
      .0012991556
       .002297359
       .003294567
       .009058844
      -.002803927
     -.0017014467
      .0021975834
       .005683817
      .0008995953
     -.0045101554
       .002297359
       .003792798
      -.007830579
      -.005716307
      -.005213567
      -.006823225
       .005286004
      -.003305457
       .004390348
     -.0013008456
      .0010993954
       .004788517
      .0009995004
        .00039992
       .007174204
       .010544213
     -.0044097085
     -.0008003202
       .008662373
       -.00040008
       .001798382
       -.01015135
     .00049987505
      -.010252376
      -.006823225
       .005783245
       .011533235
     -.0019018073
       .007868959
     -.0010005004
       -.00040008
       .007074913
      .0026963616
      -.003004509
        .00019998
       .000299955
       .005087039
        .00995033
      -.003506139
      .0045894524
       .005385472
       .002995509
       .000299955
       .005683817
      -.006923915
     -.0023026492
      -.006420568
      -.003807238
       .005882663
       .005087039
       -.00060018
     -.0020020027
     -.0040080217
        .00249688
      -.002803927
     -.0009004053
        .00039992
        .01469155
       .004888034
       .000099995
      -.003807238
      -.002603386
       -.00040008
     -.0044097085
       .006478966
      .0011992805
      -.006319929
      -.011060948
      -.011971372
      -.008939842
        .02039069
      .0015987214
      -.008939842
       .003095205
       .007571266
      -.004811557
       -.00471108
      -.003706862
       .001399021
      -.007326776
       .007472015
      .0011992805
       .008662373
      .0016985567
      -.002703652
      .0042907814
       .005087039
    -.00050012505
      -.005012542
    end

  • #2
    Stata has inbuilt commands to plot correlograms. See
    Code:
    help corrgram
    Does this suffice for your purpose?

    Comment

    Working...
    X