I have a panel data set (36 years, 120 countries). I want to check how the results change when dropping different years. Though, some of the preliminary "Basic coding & cleaning" depends on the number of years and on the particular years used.
a) How can I loop over my entire analysis and drop e.g. the most recent year in each loop?
b) How can I define the range inside the forval commands depending on the number of years used (since it will differ from 36 in each loop)?
a) How can I loop over my entire analysis and drop e.g. the most recent year in each loop?
b) How can I define the range inside the forval commands depending on the number of years used (since it will differ from 36 in each loop)?
Code:
************************************ *** Some basic coding & cleaning *** ************************************ use "FAid_Final.dta", clear tsset obs year tab cont, gen(contdum) tab year, gen(ydum) tab risocode, gen(cdum) forval x=1/36{ gen cont1_y`x'=contdum1*ydum`x' } forval x=1/36{ gen cont2_y`x'=contdum2*ydum`x' } forval x=1/36{ gen cont3_y`x'=contdum3*ydum`x' } forval x=1/36{ gen cont4_y`x'=contdum4*ydum`x' } forval x=1/36{ gen cont5_y`x'=contdum5*ydum`x' } forval x=1/36{ gen cont6_y`x'=contdum6*ydum`x' } forval x=1/36{ gen rcereal_y`x'=recipient_pc_cereals_prod_avg*ydum`x' } forval x=1/36{ gen rimport_y`x'=cereal_pc_import_quantity_avg*ydum`x' } forval x=1/36{ gen usec_y`x'=real_us_nonfoodaid_ecaid_avg*ydum`x' } forval x=1/36{ gen usmil_y`x'=real_usmilaid_avg*ydum`x' } gen USA_ln_income = ln(USA_rgdpch) bysort risocode: egen ln_rgdpch_avg=mean(ln_rgdpch) if year>=1971 & year<=2006 forval x=1/36{ gen gdp_y`x'=ln_rgdpch_avg*ydum`x' } gen oil_fadum_avg=oil_price_2011_USD*fadum_avg gen US_income_fadum_avg=USA_ln_income*fadum_avg gen US_democ_pres_fadum_avg=US_president_democ*fadum_avg local US_controls "oil_fadum_avg US_income_fadum_avg US_democ_pres_fadum_avg" local weather_controls "all_Precip_jan-all_Precip_dec all_Temp_jan-all_Temp_dec all_Precip_jan_faavg-all_Precip_dec_faavg all_Temp_jan_faavg-all_Temp_dec_faavg" local country_chars_controls "gdp_y2-gdp_y36 usmil_y2-usmil_y36 usec_y2-usec_y36" local cereals_controls "rcereal_y2-rcereal_y36 rimport_y2-rimport_y36" local baseline_controls "oil_fadum_avg US_income_fadum_avg US_democ_pres_fadum_avg gdp_y2-gdp_y36 usmil_y2-usmil_y36 usec_y2-usec_y36 rcereal_y2-rcereal_y36 rimport_y2-rimport_y36 all_Precip_jan-all_Precip_dec all_Temp_jan-all_Temp_dec all_Precip_jan_faavg-all_Precip_dec_faavg all_Temp_jan_faavg-all_Temp_dec_faavg" sor risocode year save "in_sample.dta", replace *********************************** *** TABLE 1: Summary Statistics *** *********************************** use "in_sample.dta", clear xi: ivreg2 intra_state (wheat_aid=instrument) `US_controls' i.risocode i.year*i.wb_region if year>=1971 & year<=2006, cluster(risocode)
Comment