Announcement

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

  • graph bar problem.

    Dear All, i have this data set.
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double(EINV OINV UINV) float(EINV_sig OINV_sig UINV_sig)
     .0063  -.011  .0016  0  0  0
    -.0006 -.0052  .0009  0  0  0
     .0032 -.0105  .0028  0  0  0
     .0011  -.021  .0004  0  0  0
    -.0021 -.0076      0  0  0  0
    -.0049 -.0137 -.0021  1  1 10
    -.0293 -.0565 -.0242  1  1  1
    -.0121 -.0175 -.0111  1  0  1
    -.0063 -.0103 -.0062  1  0  1
    -.0041 -.0075 -.0029  1  1  1
    -.0065 -.0104 -.0052  1  1  1
    -.0019 -.0041  .0007  0  0  0
    -.0003 -.0099  .0041  0  0  0
    -.0087 -.0399 -.0019  0  0  0
    -.0035 -.0071 -.0003  0  0  0
    -.0064  -.014 -.0026  1  1 10
    -.0752 -.1154 -.0576  1  1  1
    -.0201 -.0203 -.0166  1  0  1
    -.0088 -.0102 -.0077  1  0  1
    -.0048 -.0072 -.0032  1  1  1
    -.0077 -.0104 -.0059  1  1  1
    -.0023 -.0029      0  0  0  0
    -.0012      0   .001  0  0  0
    -.0155 -.0301 -.0085  0  0  0
    -.0161 -.0359 -.0098  1  1  5
     .0108  .0153  .0109  1  5  1
     .0124  .0087  .0144  1  0  1
     .8984  .7977 1.1072  1  0  1
    -.0062 -.0088 -.0052  1  1  1
    -.0132 -.0164 -.0122  1  1  1
     .0121  .0341  .0129  0  0  0
    -.0041 -.0065 -.0011  0  0  0
    -.0072 -.0146 -.0035  1  1  5
     .4559  .6317  .3796  1  1  1
    -.0329  -.027   -.03  1  0  1
    -.0106 -.0102 -.0101  1  0  1
     -.005 -.0071 -.0037  1  1  1
    -.0084 -.0104 -.0068  1  1  1
     -.003 -.0038 -.0002  0  0  0
    -.0062 -.0121 -.0026  1  1  5
    -.2257 -.2861 -.1836  1  5  1
    -.0236 -.0144 -.0211  1  0  1
    -.0088 -.0067 -.0083  1  0  1
    -.0046 -.0061 -.0033  1  1  1
    -.0076 -.0088 -.0061  1  1  1
    -.0163 -.0382 -.0103  1  1  5
     .0074  .0093  .0083  1  5  1
     .0072  .0014  .0101  5  0  1
     .0349  .0156   .053  5  0  1
    -.0056 -.0073  -.005  1  1  1
    -.0129 -.0144 -.0127  1  1  1
     .0015 -.0026  .0037  0  0  1
    -.0004 -.0113  .0035  0  5  5
    -.0012 -.0223  .0084  0  5  1
    -.0032 -.0007 -.0039  1  0  1
     -.011 -.0012  -.014  1  0  1
     .0078  .0279  .0042  0 10  0
     .0029  .0083  .0011  0  0  0
    -.0011 -.0016 -.0004 10  0  0
    -.0024 -.0021 -.0018  1  0  1
     .0003 -.0021 -.0005  0  0  0
    -.0021  -.005 -.0009  1  1 10
    -.0043 -.0076 -.0029  1  1  1
    -.0028 -.0058  -.001  1  1  0
    -.0067 -.0105 -.0041  1  1  1
     .0017 -.0004  .0025  0  0 10
    end
    I need to do the following for EINV, OINV, and UINV variables (probably in a single graph). Taking EINV as an example, I wish to provide count information for the positive or negative values (estimates for othe regressions), respectively.
    I also hope to offer information to show, if they are positive (negative), the number of statistically significant values (denoted by EINV_sig==1) and insignificant ones (denoted by EINV_sig==0). Any suggestions are highly appreciated.
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    Sorry, my bad. It should have been
    Code:
    I also hope to offer information to show, if they are positive (negative), the number of statistically significant values (denoted by EINV_sig>0) and insignificant ones (denoted by EINV_sig==0)
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

    Comment


    • #3
      EDIT: #2 explains the doubt in the opening comments.

      I have to doubt your description of the significance variables. The example data show distinct values 0, 1, 5, 10, which I have to guess mean something different, possibly

      10, 5, 1 significant at 10, 5, 1% levels
      0 (inconsistently???) not significant at 10% level??

      What you want for the other variables could be, at a minimum, EITHER the marginal distributions OR the joint distribution of signs. In practice some of the 8 possible combinations of signs do not occur.

      I used designplot from the Stata Journal.


      Code:
      . search designplot, sj
      
      Search of official help files, FAQs, Examples, and Stata Journals
      
      SJ-19-3 gr0061_3  . . . . . . . . . . . . . . . Software update for designplot
              (help designplot if installed)  . . . . . . . . . . . . . .  N. J. Cox
              Q3/19   SJ 19(3):748--751
              any attempt to use the missing option of graph dot,
              graph hbar, or graph bar is now ignored and advice on
              what to do instead is shown
      
      SJ-17-3 gr0061_2  . . . . . . . . . . . . . . . Software update for designplot
              (help designplot if installed)  . . . . . . . . . . . . . .  N. J. Cox
              Q3/17   SJ 17(3):779
              help file updated
      
      SJ-15-2 gr0061_1  . . . . . . . . . . . . . . . Software update for designplot
              (help designplot if installed)  . . . . . . . . . . . . . .  N. J. Cox
              Q2/15   SJ 15(2):605--606
              bug fixed for Stata 14
      
      SJ-14-4 gr0061  Design plots for graphical summary of a response given factors
              (help designplot if installed)  . . . . . . . . . . . . . .  N. J. Cox
              Q4/14   SJ 14(4):975--990
              produces a graphical summary of a numeric response variable
              given one or more factors


      Code:
      label def sign 0 "{c -}" 1 "+"
      foreach v of var *INV {
          gen sign_`v' = `v' > 0
          label var sign_`v' "`v'"
          label val sign_`v' sign
      }
      
      gen whatever = 42
      
      set scheme s1color
      designplot whatever sign_*, min(1) max(1) stat(count) variablelabels recast(hbar) bar(1, bfcolor(dkgreen*0.2)) t1title("signs of coefficients EINV, OINV, UINV") name(G1, replace) blabel(total)
      designplot whatever sign_*, min(3) max(3) stat(count) variablelabels recast(hbar) bar(1, bfcolor(dkgreen*0.2))  t1title("signs of coefficients EINV, OINV, UINV") name(G2, replace) blabel(total) ysc(r(. 46))
      Click image for larger version

Name:	river2_G1.png
Views:	1
Size:	20.4 KB
ID:	1618471

      Click image for larger version

Name:	river2_G2.png
Views:	1
Size:	20.1 KB
ID:	1618472

      Last edited by Nick Cox; 12 Jul 2021, 02:32.

      Comment


      • #4
        Dear Nick, Many thanks for your kinf reply.

        10, 5, 1 significant at 10, 5, 1% levels => YES

        0 (inconsistently???) not significant at 10% level?? => Just for my own convenience, I set the value to be 0 if the estimates are statistically insignificant (at 10% or lower).

        What you want for the other variables could be, at a minimum, EITHER the marginal distributions OR the joint distribution of signs. In practice some of the 8 possible combinations of signs do not occur. => In this case, we can consider one pair of variables at a time (say, EINV and EINV_sig), draw three same figures, and graph combine them.

        The first graph above is almost there. Taking EINV as an instance, there are 50 negative (-) estimates, some are statistically "significant", while others are statistically "insignificant". Is it possible to show this information in the same bar? Thanks a lot.

        Ho-Chuan (River) Huang
        Stata 19.0, MP(4)

        Comment


        • #5
          I would probably switch commands for the extended problem. Here I use tabplot from the Stata Journal.

          Code:
          label def sign 0 "negative" 1 "positive"
          label def yesno 1 yes 0 no
          foreach v of var *INV {
              gen sign`v' = `v' > 0
              gen yesno`v' = `v'_sig > 0
              label val yesno`v' yesno
              label var sign`v' "`v'"
              label val sign`v' sign
          }
          
          preserve
          
          gen id = _n
          
          reshape long sign yesno, i(id) j(which) string
          label var yesno "significant at 10% level?"
          set scheme s1color
          tabplot yesno sign, by(which, compact row(1) note("")) subtitle(, fcolor(none)) showval yreverse bar2(blcolor(blue) bfcolor(blue*0.2)) bar1(blcolor(red) bfcolor(red*0.2)) separate(yesno)
          Code:
          restore
          Click image for larger version

Name:	river2_G3.png
Views:	1
Size:	23.2 KB
ID:	1618484

          Comment


          • #6
            Dear Nick, This is perfect. Thanks very much.
            Ho-Chuan (River) Huang
            Stata 19.0, MP(4)

            Comment


            • #7
              Dear Nick, Is it possible to put the information (such as frequency, and/or percentage) on the bar graph?
              Ho-Chuan (River) Huang
              Stata 19.0, MP(4)

              Comment


              • #8
                #5 already shows the frequency. That's what the showval option produces. If you want to see percentages, use the percent or percent() option as well. I am guessing that you would want percent(which)

                All these options are documented in the help.

                Comment


                • #9
                  Dear Nick, Thanks a lot.It helps.
                  Ho-Chuan (River) Huang
                  Stata 19.0, MP(4)

                  Comment


                  • #10
                    Dear Nick, Is it possible to have BOTH frequency AND percernt on the bars? I tried, but failed.
                    Ho-Chuan (River) Huang
                    Stata 19.0, MP(4)

                    Comment


                    • #11
                      Indeed. There is an example of that in the help for tabplot.


                      Code:
                      * Example generated by -dataex-. For more info, type help dataex
                      clear
                      input double(EINV OINV UINV) float(EINV_sig OINV_sig UINV_sig)
                       .0063  -.011  .0016  0  0  0
                      -.0006 -.0052  .0009  0  0  0
                       .0032 -.0105  .0028  0  0  0
                       .0011  -.021  .0004  0  0  0
                      -.0021 -.0076      0  0  0  0
                      -.0049 -.0137 -.0021  1  1 10
                      -.0293 -.0565 -.0242  1  1  1
                      -.0121 -.0175 -.0111  1  0  1
                      -.0063 -.0103 -.0062  1  0  1
                      -.0041 -.0075 -.0029  1  1  1
                      -.0065 -.0104 -.0052  1  1  1
                      -.0019 -.0041  .0007  0  0  0
                      -.0003 -.0099  .0041  0  0  0
                      -.0087 -.0399 -.0019  0  0  0
                      -.0035 -.0071 -.0003  0  0  0
                      -.0064  -.014 -.0026  1  1 10
                      -.0752 -.1154 -.0576  1  1  1
                      -.0201 -.0203 -.0166  1  0  1
                      -.0088 -.0102 -.0077  1  0  1
                      -.0048 -.0072 -.0032  1  1  1
                      -.0077 -.0104 -.0059  1  1  1
                      -.0023 -.0029      0  0  0  0
                      -.0012      0   .001  0  0  0
                      -.0155 -.0301 -.0085  0  0  0
                      -.0161 -.0359 -.0098  1  1  5
                       .0108  .0153  .0109  1  5  1
                       .0124  .0087  .0144  1  0  1
                       .8984  .7977 1.1072  1  0  1
                      -.0062 -.0088 -.0052  1  1  1
                      -.0132 -.0164 -.0122  1  1  1
                       .0121  .0341  .0129  0  0  0
                      -.0041 -.0065 -.0011  0  0  0
                      -.0072 -.0146 -.0035  1  1  5
                       .4559  .6317  .3796  1  1  1
                      -.0329  -.027   -.03  1  0  1
                      -.0106 -.0102 -.0101  1  0  1
                       -.005 -.0071 -.0037  1  1  1
                      -.0084 -.0104 -.0068  1  1  1
                       -.003 -.0038 -.0002  0  0  0
                      -.0062 -.0121 -.0026  1  1  5
                      -.2257 -.2861 -.1836  1  5  1
                      -.0236 -.0144 -.0211  1  0  1
                      -.0088 -.0067 -.0083  1  0  1
                      -.0046 -.0061 -.0033  1  1  1
                      -.0076 -.0088 -.0061  1  1  1
                      -.0163 -.0382 -.0103  1  1  5
                       .0074  .0093  .0083  1  5  1
                       .0072  .0014  .0101  5  0  1
                       .0349  .0156   .053  5  0  1
                      -.0056 -.0073  -.005  1  1  1
                      -.0129 -.0144 -.0127  1  1  1
                       .0015 -.0026  .0037  0  0  1
                      -.0004 -.0113  .0035  0  5  5
                      -.0012 -.0223  .0084  0  5  1
                      -.0032 -.0007 -.0039  1  0  1
                       -.011 -.0012  -.014  1  0  1
                       .0078  .0279  .0042  0 10  0
                       .0029  .0083  .0011  0  0  0
                      -.0011 -.0016 -.0004 10  0  0
                      -.0024 -.0021 -.0018  1  0  1
                       .0003 -.0021 -.0005  0  0  0
                      -.0021  -.005 -.0009  1  1 10
                      -.0043 -.0076 -.0029  1  1  1
                      -.0028 -.0058  -.001  1  1  0
                      -.0067 -.0105 -.0041  1  1  1
                       .0017 -.0004  .0025  0  0 10
                      end
                      
                      label def sign 0 "negative" 1 "positive"
                      label def yesno 1 yes 0 no
                      foreach v of var *INV {
                          gen sign`v' = `v' > 0
                          gen yesno`v' = `v'_sig > 0
                          label val yesno`v' yesno
                          label var sign`v' "`v'"
                          label val sign`v' sign
                      }
                      
                      preserve
                      
                      gen id = _n
                      
                      reshape long sign yesno, i(id) j(which) string
                      label var yesno "significant at 10% level?"
                      set scheme s1color
                      
                      bysort which yesno sign  : gen freq = _N 
                      by which : gen total = _N 
                      gen toshow = strofreal(freq) + " (" + strofreal(100 * freq/total, "%2.1f") + "%)"
                      tabplot yesno sign, by(which, compact row(1) note("")) subtitle(, fcolor(none)) showval(toshow) yreverse bar2(blcolor(blue) bfcolor(blue*0.2)) bar1(blcolor(red) bfcolor(red*0.2)) separate(yesno)

                      Comment


                      • #12
                        Dear Nick, This is exactly what I wanted/needed. Thanks again.
                        Ho-Chuan (River) Huang
                        Stata 19.0, MP(4)

                        Comment


                        • #13
                          Dear Nick, I ran the following code (mostly from your suggestions),
                          Code:
                          cd "F:\@Unidentified\"
                          /*
                          import excel "raw\Figure1-Fan-LEV.xlsx", sheet("Sheet1") cellrange(B5:BO5) clear
                          save "dta\Figure1-Fan-LEV", replace
                          import excel "raw\Figure1-Fan-Short.xlsx", sheet("Sheet1") cellrange(B5:BO5) clear
                          save "dta\Figure1-Fan-Short", replace
                          import excel "raw\Figure1-Fan-Long.xlsx", sheet("Sheet1") cellrange(B5:BO5) clear
                          save "dta\Figure1-Fan-Long", replace
                          */
                          // Appending data
                          use "dta\Figure1-Fan-LEV", clear
                          append using "dta\Figure1-Fan-Short"
                          append using "dta\Figure1-Fan-Long"
                          
                          sxpose, clear 
                          
                          foreach v of varlist _var1 _var2 _var3 {
                              destring `v', gen(`v'1) ignore(*)
                              local function cond(strlen(`v')-strlen(subinstr(`v',"*","",.))
                              gen `v'1_sig = `function'==3,1,`function'==2,5,`function'==1,10,0)))
                          }
                          
                          drop _var1 _var2 _var3
                          
                          ren _var11* LEV*
                          ren _var21* Short_LEV*
                          ren _var31* Long_LEV*
                          
                          // keep unique coefficients
                          duplicates drop LEV Short_LEV Long_LEV, force
                          
                          // https://www.statalist.org/forums/forum/general-stata-discussion/general/1618448-graph-bar-problem
                          label def sign 0 "negative" 1 "positive"
                          label def yesno 1 yes 0 no
                          foreach v of var LEV Short_LEV Long_LEV {
                              gen sign`v' = `v' > 0
                              gen yesno`v' = `v'_sig > 0
                              label val yesno`v' yesno
                              label var sign`v' "`v'"
                              label val sign`v' sign
                          }
                          
                          preserve
                          
                          gen id = _n
                          
                          reshape long sign yesno, i(id) j(which) string
                          label var yesno "significant at 10% level?"
                          set scheme s1color
                          
                          bysort which yesno sign : gen freq = _N 
                          by which : gen total = _N 
                          gen toshow = strofreal(freq) + " (" + strofreal(100 * freq/total, "%2.1f") + "%)"
                          tabplot yesno sign, by(which, compact row(1) note("")) subtitle(, fcolor(none)) showval(toshow) yreverse bar2(blcolor(blue) bfcolor(blue*0.2)) bar1(blcolor(red) bfcolor(red*0.2)) separate(yesno)
                          
                          // Figure 1
                          graph save "Graph" "F:\@Unidentified\Figure1.gph", replace
                          graph export "F:\@Unidentified\Figure1.pdf", as(pdf) name("Graph") replace
                          and obtain

                          Click image for larger version

Name:	LEV.png
Views:	1
Size:	58.8 KB
ID:	1619131

                          I wonder if I can interchange column 2 (Long_LEV) and column 3 (Short_LEV), thanks.
                          Ho-Chuan (River) Huang
                          Stata 19.0, MP(4)

                          Comment


                          • #14
                            This is really just about data management. You need to map the string values

                            Code:
                             
                             LEV Short_LEV Long_LEV
                            to 1 2 3 using label define and encode.

                            Comment


                            • #15
                              Dear Nick, LEV Short_LEV Long_LEV are names of three variables. Can we do that (label define and encode)? This question is similar to that in #5. How can we interchange the position of OINV and UINV?
                              Last edited by River Huang; 16 Jul 2021, 03:41.
                              Ho-Chuan (River) Huang
                              Stata 19.0, MP(4)

                              Comment

                              Working...
                              X