Announcement

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

  • How to plot a figure that looks like this

    Click image for larger version

Name:	Screenshot (5).png
Views:	1
Size:	27.4 KB
ID:	1693409



    The length of the horizontal lines represent the starting and ending year of the survey period of each sample. Such a representation can be useful when each estimate is based on a pooled multiyear sample and we want to inform readers of the starting and end years of each pooled sample.

  • #2
    Code:
    clear
    sysuse nlsw88, clear
    set scheme s1mono
    
    // do some data preparation
    gen byte ttl_exp_cat = 1 if ttl_exp < 10
    replace  ttl_exp_cat = 2 if ttl_exp >= 10 & ttl_exp < 15
    replace  ttl_exp_cat = 3 if ttl_exp >= 15 & !missing(ttl_exp)
    
    label define ttl_exp_cat_lb 1 "<10" 2 "10 <= ttl_exp < 15" 3 ">=15"
    label values ttl_exp_cat ttl_exp_cat_lb
    
    // estimate the model (coeflegend makes it easier to know what the coefficients are called)
    reg wage i.collgrad##i.ttl_exp_cat i.south i.union i.race c.hours##c.hours, coeflegend
    
    // get the different coefficients and the corresponding confidence intervals
    predictnl eff=_b[1.collgrad] +                                       ///
                  _b[1.collgrad#2.ttl_exp_cat]*2.ttl_exp_cat +           ///
                  _b[1.collgrad#3.ttl_exp_cat]*3.ttl_exp_cat, ci(lb ub)
    
    // graph them              
    sort ttl_exp          
        
    twoway rarea lb ub ttl_exp if ttl_exp < 10, astyle(ci) || ///
           rarea lb ub ttl_exp if ttl_exp >= 10 & ttl_exp < 15, astyle(ci) || ///
           rarea lb ub ttl_exp if ttl_exp >= 15, astyle(ci) || ///
           line eff ttl_exp if ttl_exp < 10, lstyle(solid) || ///
           line eff ttl_exp if ttl_exp >= 10 & ttl_exp < 15, lstyle(solid) || ///
           line eff ttl_exp if ttl_exp >= 15, lstyle(solid) ///
           legend(off) ylab(,angle(0)) ytitle(regression coefficient for collgrad)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	48.1 KB
ID:	1693420
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Originally posted by Maarten Buis View Post
      Code:
      clear
      sysuse nlsw88, clear
      set scheme s1mono
      
      // do some data preparation
      gen byte ttl_exp_cat = 1 if ttl_exp < 10
      replace ttl_exp_cat = 2 if ttl_exp >= 10 & ttl_exp < 15
      replace ttl_exp_cat = 3 if ttl_exp >= 15 & !missing(ttl_exp)
      
      label define ttl_exp_cat_lb 1 "<10" 2 "10 <= ttl_exp < 15" 3 ">=15"
      label values ttl_exp_cat ttl_exp_cat_lb
      
      // estimate the model (coeflegend makes it easier to know what the coefficients are called)
      reg wage i.collgrad##i.ttl_exp_cat i.south i.union i.race c.hours##c.hours, coeflegend
      
      // get the different coefficients and the corresponding confidence intervals
      predictnl eff=_b[1.collgrad] + ///
      _b[1.collgrad#2.ttl_exp_cat]*2.ttl_exp_cat + ///
      _b[1.collgrad#3.ttl_exp_cat]*3.ttl_exp_cat, ci(lb ub)
      
      // graph them
      sort ttl_exp
      
      twoway rarea lb ub ttl_exp if ttl_exp < 10, astyle(ci) || ///
      rarea lb ub ttl_exp if ttl_exp >= 10 & ttl_exp < 15, astyle(ci) || ///
      rarea lb ub ttl_exp if ttl_exp >= 15, astyle(ci) || ///
      line eff ttl_exp if ttl_exp < 10, lstyle(solid) || ///
      line eff ttl_exp if ttl_exp >= 10 & ttl_exp < 15, lstyle(solid) || ///
      line eff ttl_exp if ttl_exp >= 15, lstyle(solid) ///
      legend(off) ylab(,angle(0)) ytitle(regression coefficient for collgrad)
      [ATTACH=CONFIG]n1693420[/ATTACH]
      Thanks Maarten. Brilliant solution.

      Comment

      Working...
      X