Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • shp2dta error: 3300 argument out of range

    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

  • #2
    I downloaded the shapefile and I get the same error when using shp2dta.

    If you have Stata 15, you can use the new spshape2dta command, which converts the shapefile without reporting an error.

    Otherwise, you can make a copy of the file "shp2dta.ado" into the current directory and change the following line (1122):
    Code:
    if (rc = _st_addvar("format", vname)<0) {
    to
    Code:
    if (rc = _st_addvar(format, vname)<0) {
    With this fix, shp2dta will process the shapefile without error and generate the same data that you would get if you were using the new spshape2dta command. The problem relates to a variable named SEDE in the database dataset. It is initially identified as an strL but the required length is calculated as 1.

    Comment


    • #3
      Dear Readers

      I have this error trying to "import dbase " - Stata 16.1, Windows 10 64bit - both up to date:

      . import dbase using "D:\temp\basins\ganges\ganges_nrldWbAg_polylines_s e2.dbf", clear case(lower)
      bufget(): 3300 argument out of range
      fbufget(): - function returned error
      import_dbase_load_fields(): - function returned error
      import_dbase_load_file(): - function returned error
      import_dbase_import_file(): - function returned error
      <istmt>: - function returned error
      r(3300);


      I get the same error using shp2dta (both with and without Robert Picard's suggestion):

      type: 3
      bufget(): 3300 argument out of range
      fbufget(): - function returned error
      read_dbf(): - function returned error
      <istmt>: - function returned error
      r(3300);

      and spshape2dta just fails:


      (importing .shp file)
      (importing .dbf file)
      could not import .dbf file
      r(3300);

      error 3300 is:

      3300. argument out of range
      The eltype and orgtype of the argument are correct, but the argument contains an invalid
      value, such as if you had asked for the 20th row of a 4 × 5 matrix.

      Any suggestions how to deal with this?

      Thanks in anticipation

      Richard






      Comment

      Working...
      X