Announcement

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

  • Observation Number out of Range r(198) Error

    Hi,

    I am importing a dataset from excel but when I am proceeding to add observations by using the command: set obs '=_N+11' I get an error stating observation number out of range. I haven't encountered this error before.

    I have set trace on at the start but cannot figure out where the problem is while exporting. The import trace commands appearing are as follows:



    - version 12
    - scalar ImpExcelCleanUp = -1
    - capture noi import_excel `macval(0)'
    = capture noi import_excel "F:\Dataset.xls", sheet("Sheet1") firstrow
    ------------------------------------------------------------------------------------- begin import_excel ---
    - version 12
    - if ("`c(excelsupport)'" != "1") {
    = if ("1" != "1") {
    dis as err `"import excel is not supported on this platform."'
    exit 198
    }
    - gettoken filename rest : 0, parse(" ,")
    - gettoken comma : rest, parse(" ,")
    - if (`"`filename'"' != "" & (trim(`"`comma'"') == "," | trim(`"`comma'"') == "")) {
    = if (`"F:\Dataset .xls"' != "" & (trim
    > (`","') == "," | trim(`","') == "")) {
    - local 0 `"using `macval(0)'"'
    = local 0 `"using "F:\Dataset.xls", sh
    > eet("Sheet1") firstrow"'
    - }
    - capture syntax using/, DESCribe
    - if _rc {
    - capture syntax using/ [, ALLSTRING(string) *]
    - local fmtstring `"`allstring'"'
    = local fmtstring `""'
    - capture syntax using/ [, SHeet(string) CELLRAnge(string) FIRSTrow ALLstring(string) ALLstring case(string)
    > locale(string) clear]
    - if _rc {
    syntax [anything(name=extvarlist id="extvarlist" equalok)] using/ [, ALLSTRING(string) *]
    local fmtstring `"`allstring'"'
    syntax [anything(name=extvarlist id="extvarlist" equalok)] using/ [, SHeet(string) CELLRAnge(string) FIRST
    > row ALLstring(string) ALLstring locale(string) clear]
    }
    - }
    - if ("`allstring'" != "" & "`fmtstring'" != "") {
    = if ("" != "" & "" != "") {
    opts_exclusive "allstring allstring()"
    }
    - mata : import_excel_import_file()
    (14 vars, 13 obs)
    --------------------------------------------------------------------------------------- end import_excel ---
    - nobreak {
    - local rc = _rc
    - if `rc' {
    = if 0 {
    if ImpExcelCleanUp >= 0 {
    mata : import_excel_cleanup()
    }
    }
    - }
    - scalar drop ImpExcelCleanUp
    - exit `rc'
    = exit 0
    -------------------------------------------------------------------------------------- end import.ImpExcel ---
    - }
    - else if `"`subcmd'"' == "fred" {
    = else if `"excel"' == "fred" {
    ImpFred `macval(0)'
    }
    - else if `"`subcmd'"' == "hav" {
    = else if `"excel"' == "hav" {
    ImpHaver `macval(0)'
    }
    - else if `"`subcmd'"' == "have" {
    = else if `"excel"' == "have" {
    ImpHaver `macval(0)'
    }
    - else if `"`subcmd'"' == "haver" {
    = else if `"excel"' == "haver" {
    ImpHaver `macval(0)'
    }
    - else if `"`subcmd'"' == "sas" {
    = else if `"excel"' == "sas" {
    ImpSas `macval(0)'
    }
    - else if `"`subcmd'"' == "sasxport5" {
    = else if `"excel"' == "sasxport5" {
    ImpSasxport5 `macval(0)'
    }
    - else if `"`subcmd'"' == "sasxport8" {
    = else if `"excel"' == "sasxport8" {
    ImpSasxport8 `macval(0)'
    }
    - else if `"`subcmd'"' == "sasxport" {
    = else if `"excel"' == "sasxport" {
    if (_caller() < 16) {
    ImpSasxport5 `macval(0)'
    }
    else {
    di as error "invalid syntax"
    di as error " specify either {cmd:import sasxport5} or {cmd:import sasxport8}"
    exit 198
    }
    }
    - else if `"`subcmd'"' == "shp" {
    = else if `"excel"' == "shp" {
    ImpShape `macval(0)'
    }
    - else if `"`subcmd'"' == "spss" {
    = else if `"excel"' == "spss" {
    ImpSpss `macval(0)'
    }
    - else {
    display as error `"import: unknown subcommand "`subcmd'""'
    exit 198
    }


    I hope this information helps.

  • #2
    When I'm using tsappend , I get the error varlist not allowed.

    - version 8.0
    - syntax , [add(passthru) last(string) tsfmt(passthru) panel(string)]

    Example of dataset created through dataex:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int year double RailFreight long(RailFreightWagons RailFreightDiesellitres RailFreightElectricityConsump) double(RailElectricityConsumptionper InlandFreightTonneKilometers) int IWTVessels float(RailFreightDiff InlandFreightDiff)
    2007 5215857.5      .          .       .    .    28064  627         .        .
    2008   5517042      .  913534000 4099564    .    29483  319  301184.5     1419
    2009 6001460.5 218312  993629000 4373371    .    37085  280  484418.5     7602
    2010 6258546.5 225259  995851000 4531833    .    40259  315    257086     3174
    2011 6676754.5 235009 1005431000 4816906    .    38098  380    418208    -2161
    2012 6492099.5 244818 1016992000 4728339    .    30629  329   -184655    -7469
    2013   6656881 245267 1017366000 4800165    .    24183  513  164781.5    -6446
    2014   6812517 254018 1024389000 5019800    .    28468  288    155636     4285
    2015 6542969.5 248725  998153000 4869619    .    34597  394 -269547.5     6129
    2016 6205501.5 275807  944311000 4016516    .    38308  516   -337468     3711
    2017   6934109 279311  979714000 4239565 5.89 41297.89  412  728607.5  2989.89
    2018   7389954 289175 1011022000 4442497 5.83 47421.54 1249    455845  6123.65
    2019 7081282.5 293077          .       . 6.13 44412.36  867 -308671.5 -3009.18
    end

    Comment

    Working...
    X