Search code examples
survivalstata

Stata: How do I clear sts graphs from memory?


I have the following code:

graph drop _all
sts graph if year==2014, saving(14)
sts graph if year==2015, saving(15)
sts graph if year==2016, saving(16)

gr combine 14.gph 15.gph 16.gph

I would like to add a line that will clear the previous graph from the memory or rewrite it.

I have tried: graph drop _all. This doesn't work. Graphs are not cleared. I have also tried putting a replace command after the codes above, like this:

sts graph if year==2014, saving(14) replace
sts graph if year==2015, saving(15) replace
sts graph if year==2016, saving(16) replace

gr combine 14.gph 15.gph 16.gph

But sts doesn't work with replace.

Any other suggestions?


Solution

  • From the manual:

    enter image description here

    The replace option should go inside the pair of parentheses. Try this:

    sts graph if year==2014, saving(14, replace) 
    sts graph if year==2015, saving(15, replace)
    sts graph if year==2016, saving(16, replace)