Dear Statalist forum,

I would like to construct a three-year average as the data is available in the three-year gap, 2011, 2014, and 2017.

I used the following state codes for the analysis. Please assist in whether I am working rightly for the average construction.

#delimit;
global xlist country code costs costr remgdp rem empe unem unemt tax_rev mob_subs port rail internet net_mig debt
mig_stoc mig_stock2 urban rural pop_dens dcps dcpsb dcpf gdp_gr gdp_c gdppc_p gdp_p saving house_exp Rearch
trade_opness second primary edu_exp edu_bac edu_sec edu_psec edu_prima edu_ter edu_ups edu_mas life_exp infc
infg bank_con accountf accountr accountw atm bran bank_con2 bank_dep bank_int_mar zscore bank_cris cred_card
debit deposit elect fsd_gdp h_stat ins_gdp int_debt ll_gdp loan_fi loan_12 mob_bill mob_mon prcrd pcmd save_12
save_fi kaopen ka_open;
#delimit cr

foreach var of varlist $xlist {
tssmooth ma x`var' = `var', w(3)
}
keep if (year==2011)| (year==2014)| (year == 2017)
gen period = 1
replace period = 1 if year == 2011
replace period = 2 if year == 2014
replace period = 3 if year == 2017

However, the average result is lower than the minimum value in three years, for example, if the value of year1 =2, year2=2.5, and for year3 = 3, than the average value must at least 2, and with the above codes, it's coming like 1.9 something.



Thanks for the assistance.