Announcement

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

  • Table of correlations and stats issue

    Hello, I am currently having an issue with my code. I am trying to code a table of descriptive data but encounter an issue.
    This is my code:

    collect create corr2
    pwcorr remote onlineagenda onlinesmalltalk Remote_Communication Remote_Problem_daydream Remote_Bizarre_daydream Remote_Creativity, sig

    matrix define vechrow = vech(r(C))'
    matrix list r(C)
    matrix list vechrow

    table (result coleq) (colname),
    statistic(mean remote onlineagenda onlinesmalltalk Remote_Communication Remote_Problem_daydream Remote_Bizarre_daydream Remote_Creativity)
    statistic(sd remote onlineagenda onlinesmalltalk Remote_Communication Remote_Problem_daydream Remote_Bizarre_daydream Remote_Creativity)
    command(corr=(vech(r(C))') sig=(vech(r(sig))'):
    pwcorr remote onlineagenda onlinesmalltalk Remote_Communication Remote_Problem_daydream Remote_Bizarre_daydream Remote_Creativity, sig) nformat(%5.2f mean sd)


    However I am blocked because of the following:
    table (result coleq) (colname),
    keyword coleq requires option command()


    I have no idea how to solve this. Can anyone help me? Thank you!

  • #2
    It is based on this:https://www.stata.com/manuals/tablesexample1.pdf

    Comment


    • #3
      In your do-file you are missing some line-continuation delimiters ///. Stata's manuals typically do not show these, but they are indicated by the leading >. In the following I added the line-continuation delimiters to the long table command.

      Code:
      collect create corr2
      pwcorr remote onlineagenda onlinesmalltalk Remote_Communication Remote_Problem_daydream Remote_Bizarre_daydream Remote_Creativity, sig
      
      matrix define vechrow = vech(r(C))'
      matrix list r(C)
      matrix list vechrow
      
      table (result coleq) (colname), ///
      statistic(mean remote onlineagenda onlinesmalltalk Remote_Communication Remote_Problem_daydream Remote_Bizarre_daydream Remote_Creativity) ///
      statistic(sd remote onlineagenda onlinesmalltalk Remote_Communication Remote_Problem_daydream Remote_Bizarre_daydream Remote_Creativity) ///
      command(corr=(vech(r(C))') sig=(vech(r(sig))'): ///
      pwcorr remote onlineagenda onlinesmalltalk Remote_Communication Remote_Problem_daydream Remote_Bizarre_daydream Remote_Creativity, sig) nformat(%5.2f mean sd)
      When faced with a list if variables that I need to repeat in multiple commands, I tend to put that list in a local macro and reference it instead. I also indent multi-line commands to help make my code more readable.

      Code:
      local vlist remote onlineagenda onlinesmalltalk Remote_Communication Remote_Problem_daydream Remote_Bizarre_daydream Remote_Creativity
      
      collect create corr2
      pwcorr `vlist', sig
      
      matrix define vechrow = vech(r(C))'
      matrix list r(C)
      matrix list vechrow
      
      table (result coleq) (colname), ///
          statistic(mean `vlist') ///
          statistic(sd `vlist') ///
          command(corr=(vech(r(C))') sig=(vech(r(sig))'): ///
              pwcorr `vlist', sig) nformat(%5.2f mean sd)

      Comment


      • #4
        Thank you so much it worked!

        Comment

        Working...
        X