Announcement

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

  • #16
    Please look at your own code. In terms of changing your graph the only details that matter are what data you have just before the graph call.

    After the reshape long you have a string variable which with distinct values

    Code:
    LEV
    Short_LEV
    Long_LEV
    and the reason your graph doesn't have panels in the order you desire is that the by() option of graph is sorting alphabetically. So, you need a different variable. Something like

    Code:
    clonevar WHICH = which
    replace WHICH = subinstr(WHICH, "_", " ", .)
    lahel def WHICH 1 LEV 2 "Short LEV" 3 "Long LEV"
    encode WHICH, gen(wanted) 
      
     tabplot yesno sign, by(wanted, compact row(1) note(""))
    with other options as before.

    Clearly I can't test anything here as I don't have access to your F: drive and you don't give a data example. I have guessed that the underscore is too ugly to be attractive in a graph and you might wish to make other changes.

    Hope that helps.
    Last edited by Nick Cox; 16 Jul 2021, 03:45.

    Comment


    • #17
      Dear Nick, Taking #11 as an example, I modified the code
      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?"
      clonevar WHICH = which
      *replace WHICH = subinstr(WHICH, "_", " ", .)
      label def WHICH 1 "EINV" 2 "UINV" 3 "OINV"
      encode WHICH, gen(wanted) 
      
      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(wanted, 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)
      The graph is as below, but the order is NOT what I expected.

      Click image for larger version

Name:	order.png
Views:	1
Size:	59.3 KB
ID:	1619146


      Any suggestions? Thanks aagain.
      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment


      • #18
        Should be

        Code:
        encode WHICH, gen(wanted) label(WHICH)

        Comment


        • #19
          Dear Nick, It works now. Thanks a lot.

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

          Comment

          Working...
          X