' Automated Graph creation: 

'Options to choose from

'Choosing the state:
%state="AK"   'input the abbreviated state name desired here
%longstate = "Alaska" 'input the full state name here

'Choosing the date range
%begindate = "2013"  ' can change if desired
%enddate = "2019"     ' can change if desired
%shadingstart = "2019"
%shadingtend = "2019"

'Subroutines that probably need to be run every time
call wf_open
call clean
call PC

'Graph subroutine
CALL graphtest

'**************************************************************************************
Subroutine wf_open

wfopen "R:\Forecasting\DEVEL\Olevia\One Drive Files\Research Projects\State Forecast Graphs\Eviews\EVWF\sample.wf1"

endsub


'**************************************************************************************
subroutine clean

for %x Var1 Var2
		for %y {%state}
		 series {%x}_value_{%y} = @recode({%x}_value_{%y} = 0,NA,{%x}_value_{%y})
			next
		next

endsub


'**************************************************************************************
'Percent change creation
Subroutine PC

for %x  Var1 Var2
		for %y {%state}
			genr {%x}_value_{%y}_pc = @pc({%x}_value_{%y})
			next
		next

endsub
'**************************************************************************************

subroutine graphtest

smpl {%begindate} {%enddate}

for %x Var1 Var2
	for %y {%state}
		group valgroup_{%x} {%x}_value_{%y} {%x}_value_{%y}_pc
		freeze(g_{%x}_value_{%y}) valgroup_{%x}.mixed bar(1) line(2)
		g_{%x}_value_{%y}.options gridnone
		g_{%x}_value_{%y}.setelem(2) axis(r) 
		g_{%x}_value_{%y}.axis(r) format(suffix="%") 
		g_{%x}_value_{%y}.axis(r) range(minmax)
		g_{%x}_value_{%y}.setelem(1) linecolor(@rgb(255,87,59))
		g_{%x}_value_{%y}.setelem(1) symbol(FILLEDCIRCLE)
		g_{%x}_value_{%y}.axis(l) linearzero
		g_{%x}_value_{%y}.axis(r) linearzero
		g_{%x}_value_{%y}.addtext(r,font(b,12)) "Percent Change"
		g_{%x}_value_{%y}.addtext(l,font(b,12)) "Level"
		g_{%x}_value_{%y}.axis overlap
		g_{%x}_value_{%y}.options barlabelabove
		g_{%x}_value_{%y}.setelem(1) fcolor(63,79,170)
		g_{%x}_value_{%y}.setelem(1) legend(Value)
		g_{%x}_value_{%y}.setelem(2) legend(Percentage Change (Y/Y))
		g_{%x}_value_{%y}.datelabel format("YYYY")
		g_{%x}_value_{%y}.draw(shade, bottom,rgb(255,255,180)) %shadingstart  %shadingend 
		next
	next
endsub
