Announcement

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

  • Profileplot color

    Dear all,
    I am struggling with adding colors to a profileplot. I have a dataset with a variable (var1) before and after a certain condition.
    My idea is to have a panel with two plots. The first would be a plot where the observations had a decreasing var1, and the second plot with all observations who had an increasing var1 (before/after). By default, profileplot add different colors to each line (observation), but I would like to add a color for all the lines in plot1, and a different in plot2.
    I tried this without success:

    profileplot var1_before var1_after if group==1, by(id) name(g1, replace) lcolor(red)
    profileplot var1_before var1_after if group==2, by(id) name(g2, replace) lcolor(blue)
    graph combine g1 g2

    Sure there is other way to plot them. Do you have any advice?
    Thanks!


    David

  • #2
    profileplot is from UCLA. The version I have is from 2011.

    https://www.stata-journal.com/articl...article=gr0041 is one earlier overview. One technique there is to use twoway pcspike. That can be used to show different colours for different groups. The rule is that showing different colours requires different variables; hence the use of separate here.

    I am using Stata 18. If you are using an earlier version, you're asked to tell us, but this should work fine in many versions before 18 so long as you specify line colours that work in your version.

    Code:
    clear 
    set obs 100 
    
    gen var1_before = rnormal()
    gen var1_after = rnormal()
    
    * you start here 
    gen x1 = 1
    gen x2 = 2 
    
    gen which = var1_after > var1_before 
    label def which 1 increased 0 decreased 
    label val which which 
    
    separate var1_before, by(which)
    
    twoway pcspike var1_before0 x1 var1_after x2  , lc(stc2) by(which, note("") legend(off)) ///
    || pcspike var1_before1 x1 var1_after x2, lc(stc1) ytitle(whatever) xtitle("") xla(1 "before" 2 "after")
    Click image for larger version

Name:	profileplot.png
Views:	1
Size:	160.8 KB
ID:	1721079

    Comment


    • #3
      Hi Nick,
      Many thanks!! Indeed, it worked perfectly fine with my data.


      David

      Comment

      Working...
      X