Announcement

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

  • How to create a table with asterisks using ranksum

    Dear Statalist forum members,

    I've been working for a while trying to solve this problem. Then, I thought that I have invested a lot of time looking for a solution and it's time to ask to this forum how to solve it.

    I have a set of variables like this (numbers are irrelevant, just given as an example):
    n year v1 v2
    1 2000 4 1
    2 2000 6 2
    3 2000 4 4
    4 2000 8 1
    1 2001 4 4
    2 2001 8 5
    3 2001 6 3
    4 2001 4 2
    Then, I generate a new variable that is 0 if a value is lower than p50 and 1 if is equal or greater that p50, by year.

    And I want to display something like this, with a set of commands (or one command, but I want the table already done). a"year" is p50 of data of that year and below p50 (marked as 0) and b"year" is the same thing but with the data marked with 1:
    a2000 b2000 sig2000 a2001 b2001 sig2001
    v1 4 7 ** 4 7 **
    v2 1 4 * 2.5 4.5
    Asterisks are: ** if p<0.05; * if p<0.1. I get this values from ranksum.

    I don't know if I have been clear enough. I hope this helps to see what I am trying to do.

    Thank you in advance,
    Jose Lorenzo.

  • #2
    I missed that I tried with eststo, estpost and esttab and I can display a2000, b2000, a2001 and b2001, and store the asterisks somehow. However, I can not display them as strings...

    Comment


    • #3
      You can try asdoc (from SSC) with option row for making highly customized tables such as yours. See this blog entry. https://fintechprofessor.com/2018/09...stata-ms-word/
      Regards
      --------------------------------------------------
      Attaullah Shah, PhD.
      Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
      FinTechProfessor.com
      https://asdocx.com
      Check out my asdoc program, which sends outputs to MS Word.
      For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

      Comment


      • #4
        I am trying to working backwards from your table. It could be just an output of list. However, I can't see where you apply ranksum and to what.

        Comment


        • #5
          Originally posted by Attaullah Shah View Post
          You can try asdoc (from SSC) with option row for making highly customized tables such as yours. See this blog entry. https://fintechprofessor.com/2018/09...stata-ms-word/
          It seems a really interesting component. I going to try it and I will give feedback to this forum in case it works. Thank you.

          Comment


          • #6
            Originally posted by Nick Cox View Post
            I am trying to working backwards from your table. It could be just an output of list. However, I can't see where you apply ranksum and to what.
            I tried "list" too, but it doesn't show what I want. About ranksum, I am trying to separate the data in two groups and check if they are statistically the same or not.

            Comment


            • #7
              You would have to create the variables to be listed. Some detailed general comments in https://www.stata-journal.com/sjpdf....iclenum=pr0053

              Comment


              • #8
                Originally posted by Nick Cox View Post
                You would have to create the variables to be listed. Some detailed general comments in https://www.stata-journal.com/sjpdf....iclenum=pr0053
                I already solved the problem with asdoc, because with list is not that simple to get what I want (I have to create a lot of local variables to not modify the database). In the future, I will do it with list, because it is a build-in command and you don't have to install anything. However, I really appreciate your comments and The Stata Journal documentation that you share. Thank you.

                Comment


                • #9
                  It would be helpful for future reference if you share the asdoc solution here.
                  Regards
                  --------------------------------------------------
                  Attaullah Shah, PhD.
                  Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
                  FinTechProfessor.com
                  https://asdocx.com
                  Check out my asdoc program, which sends outputs to MS Word.
                  For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

                  Comment


                  • #10
                    Of course!


                    Code:
                    levelsof year, local(years)
                    asdoc, row( \i, \i, 2000, \i, \i, 2001, \i) dec(0) replace
                    forval i= 1/2 {
                    foreach y in `years' {
                    quiet sum v`i' if year==`y' & group==0, detail
                    asdoc, accum(`r(p50)')
                    quiet sum v`i' if year==`y' & group==1, detail
                    asdoc, accum(`r(p50)')
                    ranksum v`i', by ( group), if year==`y'
                    local sig_num=2*normprob(-abs(r(z)))
                    local sig="\i"
                    if (`sig_num' <= 0.1 & `sig_num' > 0.05) local sig="*"
                    else if (`sig_num' <= 0.05 & `sig_num' > 0.01) local sig="**"
                    else if (`sig_num' <= 0.01 & `sig_num' >= 0) local sig="***"
                    quiet asdoc, accum(`sig')  append
                    }
                    if (`i'<2) quiet asdoc, row( v_a`i', $accum) append
                    else asdoc, row( v_a`i', $accum) append
                    }

                    Comment


                    • #11
                      Originally posted by Nick Cox View Post
                      You would have to create the variables to be listed. Some detailed general comments in https://www.stata-journal.com/sjpdf....iclenum=pr0053
                      I also worked on a list solution (it can be improved):


                      Code:
                      levelsof year, local(years)
                      * This is to get all displays in the block at the end of the execution
                      forval d= 1/1 {
                      display %4s "Var" %14s "2000" %18s "2001"
                      display %4s ""  _continue
                      foreach y in `years' {
                      display %7s "P" %7s "G" %4s "SIG" _continue
                      }
                      display
                      foreach var of varlist v1 v2 {
                      display %4s "`var'" _continue
                      foreach y in `years' {
                      forval j = 0/1 {
                      quiet sum `var' if year==`y'  & group==`j', detail
                      display %7.3f `r(p50)' _continue
                      }
                      quiet ranksum `var', by (group), if year==`y'
                      local sig_num=2*normprob(-abs(r(z)))
                      local sig="***"
                      if (`sig_num' <= 0.1 & `sig_num' > 0.05) local sig="*"
                      if (`sig_num' <= 0.05 & `sig_num' > 0.01) local sig="**"
                      if (`sig_num' <= 0.01 & `sig_num' >= 0) local sig=" ***"
                      display %4s "`sig'" _continue
                      }
                      display  
                      }
                      }

                      Comment


                      • #12
                        Please post a minimal data example too. The code above in #11 fails with the data in #1 without a variable group.

                        Comment


                        • #13
                          Yes, I forgot to post a data example. The table on the first message is just to show the data structure, the resulted signification is not that real.
                          n year v1 v2 group
                          1 2000 1 1 1
                          2 2000 0 0 0
                          3 2000 0 0 0
                          4 2000 1 1 1
                          1 2001 1 1 1
                          2 2001 0 0 0
                          3 2001 1 1 1
                          4 2001 0 0 0

                          Comment

                          Working...
                          X