Dear Statalist,
I am using shp2dta to do perform some mapping in Stata. I have many (more than hundred) shape files (.shp, .dbf, .shx) for which I am running shp2dta, and for some of them I keep getting "_st_addvar(): 3300 argument out of range" error. Below I include an example of the command that leads to this error together with Stata output (with trace set on):
. shp2dta using 11mu2500g, database("11mu2500g-db") coordinates("11mu2500g-cd")
----------------------------------------------------------------------------------------------- begin shp2dta ---
- version 9
- syntax using/ , DATAbase(string) COORdinates(string) [replace GENCentroids(name) genid(name)]
- if (strpos(`"`using'"', ".")==0) {
= if (strpos(`"11mu2500g"', ".")==0) {
- local using `"`using'.shp"'
= local using `"11mu2500g.shp"'
- }
- local shp_file `"`using'"'
= local shp_file `"11mu2500g.shp"'
- local dbf_file : subinstr local shp_file `".shp"' `".dbf"'
- confirm file `"`shp_file'"'
= confirm file `"11mu2500g.shp"'
- confirm file `"`dbf_file'"'
= confirm file `"11mu2500g.dbf"'
- preserve
- drop _all
- mata: read_shp(`"`shp_file'"')
= mata: read_shp(`"11mu2500g.shp"')
type: 5
- qui {
- compress
- tempname TEMP
- generate long `TEMP' = _n
= generate long __000000 = _n
- sort _ID `TEMP'
= sort _ID __000000
- drop `TEMP'
= drop __000000
- local cfilename : subinstr local coordinates `".dta"' `""'
- save `"`cfilename'"', `replace'
= save `"11mu2500g-cd"',
- }
- drop _all
- mata: read_dbf(`"`dbf_file'"')
= mata: read_dbf(`"11mu2500g.dbf"')
_st_addvar(): 3300 argument out of range
read_dbf(): - function returned error
<istmt>: - function returned error
------------------------------------------------------------------------------------------------- end shp2dta ---
r(3300);
Files causing the error can be found by the link.
Apparently, the problem arises when reading in the .dbf file into mata. I've tried opening these problematic .dbf files with external applications, but I don't see any apparent issues with them except that it uses cp1251 char encoding and contains diacritics symbols in Portugese (like in "Amambaí"), while the files that are working don't seem to contain those symbols.
Hence, my guess is that the special symbols cause the error. Does anyone have an idea how to deal with this? Is it possible to replace the special letters in the dbf files using Stata? Also, the amount of files implies that I am looking for an automated solution, preferably within Stata.
Thank you
I am using shp2dta to do perform some mapping in Stata. I have many (more than hundred) shape files (.shp, .dbf, .shx) for which I am running shp2dta, and for some of them I keep getting "_st_addvar(): 3300 argument out of range" error. Below I include an example of the command that leads to this error together with Stata output (with trace set on):
. shp2dta using 11mu2500g, database("11mu2500g-db") coordinates("11mu2500g-cd")
----------------------------------------------------------------------------------------------- begin shp2dta ---
- version 9
- syntax using/ , DATAbase(string) COORdinates(string) [replace GENCentroids(name) genid(name)]
- if (strpos(`"`using'"', ".")==0) {
= if (strpos(`"11mu2500g"', ".")==0) {
- local using `"`using'.shp"'
= local using `"11mu2500g.shp"'
- }
- local shp_file `"`using'"'
= local shp_file `"11mu2500g.shp"'
- local dbf_file : subinstr local shp_file `".shp"' `".dbf"'
- confirm file `"`shp_file'"'
= confirm file `"11mu2500g.shp"'
- confirm file `"`dbf_file'"'
= confirm file `"11mu2500g.dbf"'
- preserve
- drop _all
- mata: read_shp(`"`shp_file'"')
= mata: read_shp(`"11mu2500g.shp"')
type: 5
- qui {
- compress
- tempname TEMP
- generate long `TEMP' = _n
= generate long __000000 = _n
- sort _ID `TEMP'
= sort _ID __000000
- drop `TEMP'
= drop __000000
- local cfilename : subinstr local coordinates `".dta"' `""'
- save `"`cfilename'"', `replace'
= save `"11mu2500g-cd"',
- }
- drop _all
- mata: read_dbf(`"`dbf_file'"')
= mata: read_dbf(`"11mu2500g.dbf"')
_st_addvar(): 3300 argument out of range
read_dbf(): - function returned error
<istmt>: - function returned error
------------------------------------------------------------------------------------------------- end shp2dta ---
r(3300);
Apparently, the problem arises when reading in the .dbf file into mata. I've tried opening these problematic .dbf files with external applications, but I don't see any apparent issues with them except that it uses cp1251 char encoding and contains diacritics symbols in Portugese (like in "Amambaí"), while the files that are working don't seem to contain those symbols.
Hence, my guess is that the special symbols cause the error. Does anyone have an idea how to deal with this? Is it possible to replace the special letters in the dbf files using Stata? Also, the amount of files implies that I am looking for an automated solution, preferably within Stata.
Thank you

Comment