Announcement

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

  • Plotting two densities in one graph

    Hello Statalist expert,

    I'm trying to plot 2 densities in one graph, to see how the distribution is shifted through time; or the evolution of the distribution
    my code is as follows:

    Code:
     sqreg zex_pi zpi zreer zgap zgsci zpi_lte, quantile(.1 .2 .3 .4 .5 .6 .7 .8 .9) reps(100)
     //ssc install ftools
     qregplot zpi zreer zgap zgsci zpi_lte,  ols  
     
    
    ///////fitting in the skew-t distribution
    //identify structural breaks
    
    regress ex_pi core reer_gap gdp_gap gsci pi_lte, vce(robust)
    estat sbsingle
    
    ///Estimated break date: 2006q3
    gen shift=1 if Date>tq(2006q3) 
    replace shift=0 if Date<=tq(2006q3) 
    
    skewtreg ex_pi core reer_gap gdp_gap gsci pi_lte if shift ==1,difficult
    predict resid1, residuals
    predict fitted1 if e(sample)
    kdensity resid1, normal
    kdensity fitted1, kernel( gaussian) gen(x1  gaussian1)
    
    
    skewtreg ex_pi core reer_gap gdp_gap gsci pi_lte if shift ==0, difficult
    predict resid0, residuals
    predict fitted0 if e(sample)
    kdensity resid0, normal
    kdensity fitted0, kernel( gaussian) gen(x0  gaussian0)
    
     
     //entire sample
     skewtreg ex_pi core reer_gap gdp_gap gsci pi_lte, difficult
    predict resid2, residuals
    predict fitted2 if e(sample)
    kdensity resid2, normal
    kdensity fitted2, kernel(gaussian) gen(x2  gaussian2) 
    
    
    twoway (line (x0 gaussian0),  lcolor(grey))  (line (x1 gaussian1),  lcolor(cranberry)), legend(order(1 "Core-2Q, before 2006q3" 2 "Core-2Q, after 2006q3"))
    However, it keeps giving me a rotated density (see below), and I really need someone to tell me how to fix it:

    Click image for larger version

Name:	Capture1.PNG
Views:	2
Size:	81.7 KB
ID:	1683140

    Thanks in advance
    Sarah

  • #2
    why not?

    Code:
    twoway kdensity resid1 || kdensity resid2
    and dress it up accordingly?

    Comment


    • #3
      Sarah Hussein you're just specifying the variables in the wrong order. twoway line expects you to specify the y-variable first, and the x-variable second.

      Comment

      Working...
      X