Announcement

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

  • Graph with bold ylabels

    Hi all,

    I am trying to get bold ylabels in a time series graph. I had success only in xlabel , example:

    Code:
    use "http://www.princeton.edu/~otorres/Stata/date.dta", clear
    
    gen date4=_n
    gen normal= rnormal(5000, 400)
    
    replace date2=  "{bf:" + date2 + "}"
    
    ssc install labutil
    labmask date4, values(date2)
    
    line  normal date4, xlab(1(500)4500, valuelabel angle(45))  sort
       
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	30.5 KB
ID:	1587942

    I tried to use the same steps to get bold ylabels but I failed

    Code:
    gen str_normal= string(normal)
    replace str_normal=  "{bf:" + str_normal + "}"
    labmask normal, values(str_normal)
    
    may not label non-integers
    r(198);
    Thanks in advance

    Regards
    Last edited by Rodrigo Badilla; 31 Dec 2020, 08:51.

  • #2
    labmask is from the Stata Journal, as you are asked to explain (FAQ Advice #12).

    I don't understand the appeal of x axis labels 499 or 500 days apart. That approach "worked" as giving what you asked for. I suggest that a reader is more likely to see and to appreciate simple year labels here. A little machinery yields ticks at year ends and labels at year middles.

    The approach didn't work for your y axis labels, presumably, because only by an extraordinary coincidence woutld 3000(1000)7000 be values in your data for that variable.

    Here is some different technique.
    mylabels (SSC) has some use, while you can always write a loop around the labels you want. Those aren't two different answers, as mylabels is just a convenience wrapper for a loop.

    See also https://www.stata-journal.com/articl...article=gr0030 and https://www.stata-journal.com/articl...article=gr0079

    I am agnostic about bold labels myself, as it seems simpler just to focus on how many labels you show and how big they have to be to make them readable.

    Code:
    use "http://www.princeton.edu/~otorres/Stata/date.dta", clear
    
    gen date4 = daily(date2, "MDY")
    set seed 2803 
    gen normal= rnormal(5000, 400)
    
    * ssc install mylabels 
    mylabels 4000(500)6000, prefix("{bf:") suffix("}") local(yla) 
    
    local xla 
    
    forval y = 1995/2007 { 
         local xticks `xticks' `=mdy(1,1,`y')'
        
        local T = mdy(7,1,`y')
        local Y : di %tyYY `=year(`T')'
        local xla `xla' `T' "{bf:`Y'}"
        
    }
    
    local xticks `xticks' `=mdy(1,1, 2008)'
    set scheme s1color 
    line normal date4 , yla(`yla', ang(h)) xla(`xla', tlength(*0.2) tlc(none)) xticks(`xticks', tlength(*3)) xtitle("")


    Click image for larger version

Name:	boldlabels.png
Views:	1
Size:	103.0 KB
ID:	1587945

    Comment


    • #3
      Thanks Nick Cox for you reply, work perfect.

      I will take your point.

      500 days was only used to display properly x axis labels, to give a better example of my problem.

      Code:
      line  normal date4, xlab(, valuelabel angle(45))  sort
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	27.6 KB
ID:	1587951



      Regards
      Last edited by Rodrigo Badilla; 31 Dec 2020, 10:07.

      Comment

      Working...
      X