Hello Stata Users,
I am trying to reproduce the results of a recent paper : Gendron-Carrier et al. 2022. "Subways and Urban Air Pollution." AEJ : Applied Economics.
They have one main do-file running other do-files and I have some questions, I am using Stata 17 SE.
I must admit that I am not avery experienced Stata-user and, although I thoroughly searched for answers to these problems, I could not find any satisfying solution.
1) I am having some trouble to locate precisely the errors of the code when I run it, especially in which do-file they are located as I have one do-file running the others. I saw some posts about the command set trace on but it does not seem to do anything in my case. Would you have any advice?
2) I have a r(199) error in a loop because of a misplaced "/" but I don't where it could possibly be..
Thanks for reading and please allow me to present my excuses if my questions seem trivial to you.
I am trying to reproduce the results of a recent paper : Gendron-Carrier et al. 2022. "Subways and Urban Air Pollution." AEJ : Applied Economics.
They have one main do-file running other do-files and I have some questions, I am using Stata 17 SE.
I must admit that I am not avery experienced Stata-user and, although I thoroughly searched for answers to these problems, I could not find any satisfying solution.
1) I am having some trouble to locate precisely the errors of the code when I run it, especially in which do-file they are located as I have one do-file running the others. I saw some posts about the command set trace on but it does not seem to do anything in my case. Would you have any advice?
2) I have a r(199) error in a loop because of a misplaced "/" but I don't where it could possibly be..
Code:
if 1 == 1 {; global samples "subways"; foreach sample of global samples {; ${output}${date}_validation_dataset.dta, clear; if "`sample'" == "subways" {; *keep only subway cities; keep if sample_subways == 1; }; if "`sample'" == "opening" {; *keep only subway cities; keep if sample_opening == 1; }; label var aod_mean_${ring}_Terra "AOD"; label var aod_mean_${ring}_Aqua "AOD"; foreach sat in "Aqua" "Terra" {; foreach PM in "PM10" "PM25" {; preserve; keep if aod_mean_${ring}_`sat' !=. & `PM' !=.; sort urbancode; by urbancode: gen count_cities = _n; replace count_cities = 0 if count_cities >1; gen count_city_years = 1; collapse (mean) year `PM' aod_mean_${ring}_`sat' ${${pre_x_}C2_${ring}} ${${pre_x_}C4} aod_count_${ring}_`sat' (sum) count_city_years count_cities; gen year2 = int(year); drop year; rename year2 year; rename `PM' pm; rename aod_mean_${ring}_`sat' aod; rename aod_count_${ring}_`sat' count; gen PM_str = "`PM'"; gen sat_str = "`sat'"; gen ring_str = "$ring"; order PM_str sat_str ring_str count_cities count_city_years year pm aod count; save temp3/`PM'_`sat'_${ring}.dta, replace; restore; }; }; foreach sat in "Aqua" "Terra" {; foreach PM in "PM10" "PM25" {; if "`sat'" == "Aqua" & "`PM'" == "PM10" {; use temp3/`PM'_`sat'_${ring}.dta, clear; }; else {; append using temp3/`PM'_`sat'_${ring}.dta; }; }; }; egen label = concat(PM_str sat_st ring_str); gen table_sort = 0; replace table_sort = 1 if label == "PM10Terra${ring}"; replace table_sort = 2 if label == "PM10Aqua${ring}"; replace table_sort = 3 if label == "PM25Terra${ring}"; replace table_sort = 4 if label == "PM25Aqua${ring}"; sort table_sort; order table_sort; drop label PM_str sat_st ring_str; xpose, clear varname; compress; set trace on outsheet using ${output}/`sample'_${ring}_summary_stats_aod_validation${foot}.xls,replace; }; };if 1 == 1 {; global samples "subways"; foreach sample of global samples {; ${output}${date}_validation_dataset.dta, clear; if "`sample'" == "subways" {; *keep only subway cities; keep if sample_subways == 1; }; if "`sample'" == "opening" {; *keep only subway cities; keep if sample_opening == 1; }; label var aod_mean_${ring}_Terra "AOD"; label var aod_mean_${ring}_Aqua "AOD"; foreach sat in "Aqua" "Terra" {; foreach PM in "PM10" "PM25" {; preserve; keep if aod_mean_${ring}_`sat' !=. & `PM' !=.; sort urbancode; by urbancode: gen count_cities = _n; replace count_cities = 0 if count_cities >1; gen count_city_years = 1; collapse (mean) year `PM' aod_mean_${ring}_`sat' ${${pre_x_}C2_${ring}} ${${pre_x_}C4} aod_count_${ring}_`sat' (sum) count_city_years count_cities; gen year2 = int(year); drop year; rename year2 year; rename `PM' pm; rename aod_mean_${ring}_`sat' aod; rename aod_count_${ring}_`sat' count; gen PM_str = "`PM'"; gen sat_str = "`sat'"; gen ring_str = "$ring"; order PM_str sat_str ring_str count_cities count_city_years year pm aod count; save temp3/`PM'_`sat'_${ring}.dta, replace; restore; }; }; foreach sat in "Aqua" "Terra" {; foreach PM in "PM10" "PM25" {; if "`sat'" == "Aqua" & "`PM'" == "PM10" {; use temp3/`PM'_`sat'_${ring}.dta, clear; }; else {; append using temp3/`PM'_`sat'_${ring}.dta; }; }; }; egen label = concat(PM_str sat_st ring_str); gen table_sort = 0; replace table_sort = 1 if label == "PM10Terra${ring}"; replace table_sort = 2 if label == "PM10Aqua${ring}"; replace table_sort = 3 if label == "PM25Terra${ring}"; replace table_sort = 4 if label == "PM25Aqua${ring}"; sort table_sort; order table_sort; drop label PM_str sat_st ring_str; xpose, clear varname; compress; set trace on outsheet using ${output}/`sample'_${ring}_summary_stats_aod_validation${foot}.xls,replace; }; };if 1 == 1 {; global samples "subways"; foreach sample of global samples {; ${output}${date}_validation_dataset.dta, clear; if "`sample'" == "subways" {; *keep only subway cities; keep if sample_subways == 1; }; if "`sample'" == "opening" {; *keep only subway cities; keep if sample_opening == 1; }; label var aod_mean_${ring}_Terra "AOD"; label var aod_mean_${ring}_Aqua "AOD"; foreach sat in "Aqua" "Terra" {; foreach PM in "PM10" "PM25" {; preserve; keep if aod_mean_${ring}_`sat' !=. & `PM' !=.; sort urbancode; by urbancode: gen count_cities = _n; replace count_cities = 0 if count_cities >1; gen count_city_years = 1; collapse (mean) year `PM' aod_mean_${ring}_`sat' ${${pre_x_}C2_${ring}} ${${pre_x_}C4} aod_count_${ring}_`sat' (sum) count_city_years count_cities; gen year2 = int(year); drop year; rename year2 year; rename `PM' pm; rename aod_mean_${ring}_`sat' aod; rename aod_count_${ring}_`sat' count; gen PM_str = "`PM'"; gen sat_str = "`sat'"; gen ring_str = "$ring"; order PM_str sat_str ring_str count_cities count_city_years year pm aod count; save temp3/`PM'_`sat'_${ring}.dta, replace; restore; }; }; foreach sat in "Aqua" "Terra" {; foreach PM in "PM10" "PM25" {; if "`sat'" == "Aqua" & "`PM'" == "PM10" {; use temp3/`PM'_`sat'_${ring}.dta, clear; }; else {; append using temp3/`PM'_`sat'_${ring}.dta; }; }; }; egen label = concat(PM_str sat_st ring_str); gen table_sort = 0; replace table_sort = 1 if label == "PM10Terra${ring}"; replace table_sort = 2 if label == "PM10Aqua${ring}"; replace table_sort = 3 if label == "PM25Terra${ring}"; replace table_sort = 4 if label == "PM25Aqua${ring}"; sort table_sort; order table_sort; drop label PM_str sat_st ring_str; xpose, clear varname; compress; set trace on outsheet using ${output}/`sample'_${ring}_summary_stats_aod_validation${foot}.xls,replace; }; };
Comment