Pre-treatment fit index for SCM

/*
This .do file computes the pre-treatment fit index proposed by Adhikari and Alm (2016) using the Stata sample dataset provided by Abadie et al. (2010). 
Author: Bibek Adhikari.
*/

clear all
** download data and declare panel
	sysuse smoking, clear
	xtset state year

** define synth parameters
	local outcome "cigsale"
	local treatment_year = 1989
	local treatment_unit = 3
	local first_year = 1970

** run synth
	synth `outcome' `outcome' cigsale(1988) cigsale(1980) cigsale(1975) beer lnincome retprice age15to24, trunit(`treatment_unit') trperiod(`treatment_year') fig

** store rmspe in scalar
	scalar rmspe = e(RMSPE)[1,1]

** create benchmark rmspe
	gen outcome_square = `outcome'*`outcome'
	sum outcome_square if year<`treatment_year' & year >= `first_year' & state==`treatment_unit'
	scalar benchmark_rmspe = sqrt(r(mean))

** calculate fit index
	scalar fit_index = round(rmspe/benchmark_rmspe,0.001)
	
** Display them all
	di "actual rmspe is " rmspe
	di "benchmark_rmspe is " benchmark_rmspe	
	di "pre-treatment fit index is " fit_index