Search

# Including years in your graph title in Stata

Below is a worked example, I have included 12 months in each year to the title. The graph shows clearly the trend of our variable, makes it easier to visualise any increase or decrease in the amount over the 2 years:

The commands that I used in a do-file are:

```clear

inp str10 date ricepr
"01/01/2006"   700
"01/02/2006"   700
"01/03/2006"   900
"01/04/2006"   900
"01/05/2006"   900
"01/06/2006"   900
"01/07/2006"   900
"01/08/2006"   933.33
"01/09/2006"   1000
"01/10/2006"   1000
"01/11/2006"   1000
"01/12/2006"   1000
"01/01/2007"   1050
"01/02/2007"   1087.5
"01/03/2007"   1100
"01/04/2007"   1100
"01/05/2007"   1100
"01/06/2007"   1100
"01/07/2007"   1175
"01/08/2007"   1200
"01/09/2007"   1200
"01/10/2007"   1300
"01/11/2007"   1400
"01/12/2007"   1400
end

gen int year =yofd(date(date, "DMY"))
gen byte aux=_n

//from http://www.stata-journal.com/sjpdf.html?articlenum=pr0013
//generate label for months
token `c(Mons)'

forv i = 1/24{
if `i'==1 la def month `i' "`=year[`i']' ``i''" , modify
if inrange(`i',2,12) la def month `i' "``i''" , modify
if `i'==13 la def month `i' "`=year[`i-12']' ``=`i'-12''" , modify
if `i'>13 la def month `i' "``=`i'-12''" , modify
}

label value aux month

twoway (line ricepr aux), xlabel(#24, labsize(small) ///
angle(forty_five) valuel) xtitle("")

```

For more useful tips on Stata graphs, please have a look at the book Speaking Stata Graphics