Announcement

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

  • How to adjust (select or handpick) correlation matrix column(s) output to be esttab after estpost correlation table?

    Dear Statalisters,

    I would like to find out whether it is possible to select the specific column(s) to be produced in the correlation matrix output.

    Supposedly:
    Code:
    estpost correlate var1-var20, matrix
    esttab . using CorrTable.tex, replace
    The code above produces the same number of columns for every var in [varlist].

    To illustrate:
    Code:
    Variable | var1 | var2 | var3 | var4 | var5 | var6 | var7 | var8 | var9 | var10 | ... | var20
    var1
    var2
    var3
    var4
    var5
    var6
    var7
    var8
    var9
    var10
    .
    .
    .
    var20
    The output I'm looking for is, vertically, it will initially consist of all variables listed (var1 to var20), but for horizontally, I would like to handpick which column order to be produced (i.e. var1 to var5). I will then remove some vars from the [varlist] according to what I have produced horizontally on the previous table so then I can make separate esttab outputs after a specific order/sequence. The illustration on the order of the codes will be something like this:

    Code:
    estpost correlate var1-var20, matrix // First Sequence with var1-var5 on the columns
    esttab . using CorrTable1.tex, replace
    
    estpost correlate var6-var20, matrix // Second Sequence with var6-var10 on the columns
    esttab . using CorrTable2.tex, replace
    
    estpost correlate var11-var20, matrix // Third Sequence with var11-var15 on the columns
    esttab . using CorrTable3.tex, replace
    
    estpost correlate var16-var20, matrix // Fourth Sequence with var16-var20 on the columns
    esttab . using CorrTable4.tex, replace
    Obviously, the codes above will not produce the output I want (except for the Fourth Sequence, it will do just fine; see the table outline illustrated below), as it is just to illustrate the order of correlation tables I intend to produce using esttab command. Notice that I only include the variables that have not been on the First Sequence's columns to be on the Second Sequence, etc. In order to provide a clearer picture, the table layout I am looking for will look like this:

    First Sequence:
    Code:
    Variables | var1 | var2 | var3 | var4 | var5
    var1
    var2
    var3
    var4
    var5
    var6
    var7
    var8
    var9
    var10
    var11
    var12
    var13
    var14
    var15
    var16
    var17
    var18
    var19
    var20
    Second Sequence:
    Code:
    Variables | var6 | var7 | var8 | var9 | var10
    var6
    var7
    var8
    var9
    var10
    var11
    var12
    var13
    var14
    var15
    var16
    var17
    var18
    var19
    var20
    Third Sequence:
    Code:
    Variables | var11 | var12 | var13 | var14 | var15
    var11
    var12
    var13
    var14
    var15
    var16
    var17
    var18
    var19
    var20
    Fourth Sequence:
    Code:
    Variables | var16 | var17 | var18 | var19 | var20
    var16
    var17
    var18
    var19
    var20
    My apologies for using the code delimiter to illustrate the table output. Obviously, it is not a sequence of codes, but I hope you understand I am trying to describe the correlation output table that I would like to very much produced. Any help will be much appreciated. Thank you so much and cheers!

    Best,
    Nampuna
    Last edited by Nampuna D. Gultom; 30 Mar 2021, 20:55.

  • #2
    cpcorr from SSC may help (https://www.statalist.org/forums/for...f-correlations)

    Comment


    • #3
      Nick Cox Thank you for your reply, Nick. I'm a big fan.

      Yes, I am aware of the cpcorr command and it certainly works to display the correlation coefficients exactly the way I want it. However, when I want to get the results out using esttab to get a .tex output, that's where I have the real problem since I don't think esttab is able to capture the results from cpcorr due to perhaps compatibility issue? I could be wrong about this since you wrote the cpcorr in the first place anyway. May I ask you if there is a way to capture the correlation coefficients from cpcorr to either esttab or other options?

      Best,
      Nampuna
      Last edited by Nampuna D. Gultom; 31 Mar 2021, 03:58. Reason: Fixing typos

      Comment


      • #4
        Sorry to disappoint, but I am only answering part of your question, specifically

        I would like to find out whether it is possible to select the specific column(s) to be produced in the correlation matrix output.
        As my link explains, cpcorr goes back to 2001 and bears no reference to Ben Jann's later excellent work. Believe it or not, I have never used any of that suite, which is no reflection on their quality but just a quite different detail to do with what I do and do not include in my papers. .I haven't looked but I wouldn't be at all surprised that -- to get Stata produce exactly what you want -- the best you could do is to extend Ben's code yourself.

        That could be hours or days of work, depending.

        But what's missing here? If I understand correctly, it's just a few lines of TeX or LaTeX for use downstream. Odds are that you can take the kind of mark-up that you know how to produce and just edit according to the rows and columns you want to display. That should be a few minutes' work.

        Comment


        • #5
          Nick Cox I totally understand your point of view on this matter. I have just learned LaTeX for two weeks now, and I am still not familiar with most things in that environment, hence my question on producing the correlation table in Stata (an environment I am most comfortable with) as I was required to produce a lot of correlation tables all at once in a specific format, so then I could compile all the tables in LaTeX rather quickly. That's definitely the next priority on my to-do list to learn how to do it properly in LaTeX.

          Thank you so much for your kind reply.

          Best,
          Nampuna
          Last edited by Nampuna D. Gultom; 31 Mar 2021, 04:58. Reason: Adding a few extra details.

          Comment


          • #6
            I also want to know whether esttab can do this or does it has such future plan?
            @Nils Enevoldsen Thanks so much!

            Comment

            Working...
            X