Dear Stata users,
The question is about using a loop to perform -shp2dta- (SSC) command. I have several .shp files of different provinces and of different levels. Of provinces, they are for example, Qinghai, Shaanxi, Shanghai, Shanxi, Sichuan, Tianjin, Xinjiang, Yunnan, Zhejiang. Of levels, they are state, city, and county. Those .shp files' name are combination of province and level, for example, Qinghai_state.shp, Qinghai_city.shp, Qinghai_county.shp and the likes. The basic -shp2dta- code that transforming .shp files into .dta files is:
thus for the three files of Qinghai province, the transforming codes should be:
As I have so many .shp files of different provinces and levels, I seek to perform this transforming task in a loop. And not surprisingly I failed. Belows is one of my tries. Hope someone can help me.
The question is about using a loop to perform -shp2dta- (SSC) command. I have several .shp files of different provinces and of different levels. Of provinces, they are for example, Qinghai, Shaanxi, Shanghai, Shanxi, Sichuan, Tianjin, Xinjiang, Yunnan, Zhejiang. Of levels, they are state, city, and county. Those .shp files' name are combination of province and level, for example, Qinghai_state.shp, Qinghai_city.shp, Qinghai_county.shp and the likes. The basic -shp2dta- code that transforming .shp files into .dta files is:
Code:
shp2dta using shpfilename, data(newfilename1) coor(newfilename2)
Code:
shp2dta using Qinghai_state, data(Qinghaistate_label) coor(Qinghaistate_map) shp2dta using Qinghai_city, data(Qinghaicity_label) coor(Qinghaicity_map) shp2dta using Qinghai_county, data(Qinghaicounty_label) coor(Qinghaicounty_map)
Code:
local province "Qinghai Shaanxi Shanghai Shanxi" local maptype "state city county" forvalues n = 1/4 { forvalues t = 1/3 { local pro: word `n' of `province' local map: word `t' of `maptype' display "`pro'" "_" "`map'" shp2dta using "`pro'" "_" "`map'", data("`pro'" "`map'" "_label") coor("`pro'" "`map'" "_map") local n = `n'+1 local t = `t'+1 } }
Comment