Announcement

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

  • Add trend line to bar graph

    Hi

    I would like to add a trend line to a bar graph like this

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	17.6 KB
ID:	1292982


    I use the following code

    Code:
    graph bar (mean) alpha_10sq, over(portfolios) bar(1, color(gs0)) ///
    ylab(-0.5(0.2)0.5, nogrid)
    I tried it with the "twoway" function, but I think "lfit" is not compatible with "grahp bar".

    Any idea?

    Many thanks

  • #2
    You can use twoway bar.

    Code:
    . sysuse citytemp, clear
    (City Temperature Data)
    
    . qui sum tempjuly
    
    . gen deviation = tempjuly - r(mean)
    (2 missing values generated)
    
    . collapse devi, by(div)
    
    . sort dev
    
    . gen id = 10 -_n
    
    . twoway bar devi id, barw(.5)  fcolor(*.1) || lfit dev id, lw(medthick) || , legend(off)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	12.6 KB
ID:	1292987

    Comment

    Working...
    X