Announcement

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

  • Using splitvallabels + catplot without over option

    Dear all,

    When creating graphs I often use splitvallabels to break up longer labels on the y axis. However, this only works when having something like this:

    splitvallabels rep78 , length(11)
    graph bar mpg , over(rep78, relabel(`r(relabel)') )

    My code is as follows:

    catplot var1 var2 if var3 == 1 & var1 > 0, percent(var1) asy recast (hbar) ///
    title("XXX", size(medium) span margin(b=10)) ytitle("YYY") legend( bmargin(t=1) bexpand span size(small)) ///
    aspect(0.25) ysize(2) xsize(2.8) scale(*0.75)

    You see that I do not use the over option, so that I cannot include relabel(`r(relabel)'). Does anyone have an idea on how to tackle this issue?



  • #2
    Please cite the provenance of community-contributed commands you use and give a reproducible data example. FAQ Advice #12 explains.

    Comment


    • #3
      Sorry! Hope this is better:

      I am using splitvallabels and catplot from SSC in Stata 16.1. Unfortunately, my data is confidential, so I cannot use dataex.

      All variables used in this example are numeric. Var1 is a dummy variable with three categories, var2 is a dummy variable with four categories and var3 is a dummy variable with two categories. Var1 determines whether there is a specific regulation for a firm, all firms either have regulation A, regulation B or both. Var2 determines which kind of labour agreement the firm has or whether it has none (three categories for three different agreements and one category for no agreement). Var3 simply determines whether a firm employs temporary staff.

      Descriptive and regression results show that having labour agreement 3 leads to a higher frequency of regulation A, B, and both. I illustrate this with a bar graph using the catplot command. My graph is almost fine, however, one of labour agreement name (label on the y axis) is too long, so that it is not fully displayed. Normally, I use the splitvallables command to tackle this issue. But as you can see in my code below, this does not work, if I do not indicate the over option when using the catplot command. Normally, it works like this:

      Code:
      splitvallabels var2 , length(11)
      catplot var1, over(var2, relabel(`r(relabel)') )
      But in my code, I do not use the over option, so my question is how I can still break a the long label. My code is as follows:

      Code:
      sscinstall catplot
      sscinstall splitvallabels
      
      use "$data.dta", clear
      
      catplot var1 var2 if var3 == 1 & var1 > 0, percent(var1) asy recast (hbar) ///
      title("XXX", size(medium) span margin(b=10)) ytitle("YYY") legend( bmargin(t=1) bexpand span size(small)) ///
      aspect(0.25) ysize(2) xsize(2.8) scale(*0.75)

      Comment


      • #4
        We have already addressed the first problem. https://www.statalist.org/forums/help#stata (emphasis added)

        We can understand your dataset only to the extent that you explain it clearly.

        The best way to explain it is to show an example. The community-contributed command dataex makes it easy to give simple example datasets in postings. It was written to support Statalist and its use is strongly recommended. Usually a copy of 20 or so observations from your dataset is enough to show your problem. See help dataex for details.

        [...]

        If your dataset is confidential, then provide a fake example instead.

        The second best way to explain your situation is to use one of Stata's own datasets and adapt it to your problem. Examples are the auto data and the Grunfeld data (a simple panel dataset). That may be more work for you and you may not find an analog of your problem with such a dataset.


        I have a rough idea of what the problem is, but this is a volunteer site and following your description and creating a fake dataset to explore it does not appeal. Sorry, but the terms of engagement have made been clear. Without a clear question and a clear example, your chance of a good answer decreases dramatically.

        Comment


        • #5
          Dear Nick, sorry for being so unclear.

          My last attempt. I adapted the the auto dataset as follows. As you see, one label is too long and I want to break it up:

          Code:
          set more off
          set linesize 255
          clear all
          
          use "auto.dta", clear
          
          ssc install catplot, replace
          ssc install splitvallabels, replace
          ssc install grstyle, replace
          ssc install palettes, replace
          ssc install colrspace, replace
          ssc install sxpose, replace
          net install grc1leg, from(http://www.stata.com/users/vwiggins) replace
          
          grstyle init
          grstyle set legend 12, nobox
          grstyle set color economist
          grstyle color background white
          
          rename rep78 var1
          
          recode var1 (.=1)
          label define newlabel 1 "A" 2 "B" 3 "C" 4 "very very very very very long label", modify
          label value var1 newlabel
          keep if var1 <5
          
          gen var2 = .
          replace var2 = 1 if mpg <=18
          replace var2 = 2 if mpg >= 19
          replace var2 = 3 if mpg >= 22
          
          gen var3 = .
          replace var3 = 0 if foreign == 1
          replace var3 = 1 if foreign == 0
          
          catplot var2 var1 if var3 == 1, percent(var2) asy recast (hbar) ///
          title("XXX", size(medium) span margin(b=10)) ytitle("YYY") legend( bmargin(t=1) bexpand span size(small)) ///
          aspect(0.25) ysize(2) xsize(2.8) scale(*0.75)

          Comment


          • #6
            Thanks; that is now reproducible although it seems one doesn't need grc1leg or sxpose.

            If you focus on

            Code:
            catplot var2 var1 if var3 == 1, percent(var2) asy recast (hbar) ///
            title("XXX", size(medium) span margin(b=10)) ytitle("YYY") legend( bmargin(t=1) bexpand span size(small)) ///
            aspect(0.25) ysize(2) xsize(2.8) scale(*0.75) name(G1)
            
            catplot var2  if var3 == 1, over(var1) percent(var2) asy recast (hbar) ///
            title("XXX", size(medium) span margin(b=10)) ytitle("YYY") legend( bmargin(t=1) bexpand span size(small)) ///
            aspect(0.25) ysize(2) xsize(2.8) scale(*0.75) name(G2)
            you'll note that the second is almost the same as the first, which should open a door for what you want. Otherwise note the option var1subopts() in catplot.

            Comment


            • #7
              Thanks a lot Nick, I knew there was a simple solution. One more question: It appears that there is the label of var1 next to the y axis on the left hand side of the graph. Do you know how I can get rid of it?

              Comment


              • #8
                Good. On your new question, see the help.

                Note: any categorical axis title that appears by default is produced by l1title() with hbar or dot or by b1title() with bar or the (otherwise
                undocumented) vertical option.

                Comment

                Working...
                X