Hi everyone,
I have the below code that I run for each country_origin separately. I would like to replicate this code for a large group of country_origin in one step (a simplified example for the group of country_origin could be "AFG" "ALB" "AGO" "ATG").
That's an example of the code for "AFG"
import delimited "$mydir\labels_T.txt"
drop v2 v3 v5
rename v4 v2
gen `c(obs_t)' index = _n
tempfile holding
save `holding'
drop index
rename v1 country_origin
rename v2 sector_origin
merge 1:1 _n using "$mydir\data.dta", assert(match) nogenerate
keep if country_origin=="AFG"
reshape long v, i(country_origin sector_origin) j(index)
merge m:1 index using `holding', assert(match) nogenerate
drop index
rename v1 country_destination
rename v2 sector_destination
rename v value
order value, last
sort country_origin sector_origin country_destination sector_destination
generate year=2010
save "$mydir\AFG.dta"
The code as it stands ends by saving a data file for this country_origin ("AFG" in the previous example).
I thought that one way to replicate the code would be to create a local with the different country_origin and then run a loop like this for example:
countries "AFG ALB AGO ATG"
foreach x of local countries{
}
My problem is that the code would get blocked at the save step. I need to save one separate dta file for each country_origin.
I would be grateful if you could advise.
Many thanks in advance.
I have the below code that I run for each country_origin separately. I would like to replicate this code for a large group of country_origin in one step (a simplified example for the group of country_origin could be "AFG" "ALB" "AGO" "ATG").
That's an example of the code for "AFG"
import delimited "$mydir\labels_T.txt"
drop v2 v3 v5
rename v4 v2
gen `c(obs_t)' index = _n
tempfile holding
save `holding'
drop index
rename v1 country_origin
rename v2 sector_origin
merge 1:1 _n using "$mydir\data.dta", assert(match) nogenerate
keep if country_origin=="AFG"
reshape long v, i(country_origin sector_origin) j(index)
merge m:1 index using `holding', assert(match) nogenerate
drop index
rename v1 country_destination
rename v2 sector_destination
rename v value
order value, last
sort country_origin sector_origin country_destination sector_destination
generate year=2010
save "$mydir\AFG.dta"
The code as it stands ends by saving a data file for this country_origin ("AFG" in the previous example).
I thought that one way to replicate the code would be to create a local with the different country_origin and then run a loop like this for example:
countries "AFG ALB AGO ATG"
foreach x of local countries{
}
My problem is that the code would get blocked at the save step. I need to save one separate dta file for each country_origin.
I would be grateful if you could advise.
Many thanks in advance.
Comment