Announcement

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

  • wbopendata error

    Hi, all:

    I am using wbopendata command to analyze the world bank data. however, I can not get access to any of the data, it always return “file C:\Users\JINXIA~1\AppData\Local\Temp\ST_00000002.t mp not found r(601);". It has been successfully installed. Can you figure it out? Thank you! (Stata version is 12)

    Xiaochi

  • #2
    Xiaochi,

    At first glance, this appears to be a problem with your access to the Stata temporary directory, rather than a problem with wbopendata. However, a quick Google search suggests that others have had this problem with wbopendata as well. Here are some things to try:
    • ​Make sure your Stata installation is up to date
    • Make sure you are using the latest version of wbopendata (adoupdate wbopendata)
    • Make sure you have access to the Stata temporary directory or change the Stata temporary directory to a different locations (see http://www.stata.com/support/faqs/da...ment-variable/)
    • If none of the above works, set trace on and then run wbopendata and report back to us the code that caused the error.
    Regards,
    Joe

    Comment


    • #3
      Hi, Joe:

      Thank you for your advice. I have checked steps you mentioned. Version is stata 12, tempfile works well and wbopendata doesn't need upgrade (version 9.0). but problem still exists. Here is a part of the code:

      tempfile temp
      - loc servername "http://api.worldbank.org/"
      - if (("`country'" != "") | ("`topics'" != "")) & ("`indicator'" == "") {
      = if (("All" != "") | ("" != "")) & ("" == "") {
      - capture : copy "`servername'/`language'/`parameter'?format=csv" `temp'
      = capture : copy "http://api.worldbank.org//en/Countries/All?format=csv" C:\Users\JINXIA~1\AppData\Local\Temp\ST_00000001.t mp
      - }
      - if ("`indicator'" != "") {
      = if ("" != "") {
      capture : copy "`servername'/`language'/countries/`country2'/`parameter'format=csv" `temp'
      }
      - insheet using `temp', `clear' name
      = insheet using C:\Users\JINXIA~1\AppData\Local\Temp\ST_00000001.t mp, name
      file C:\Users\JINXIA~1\AppData\Local\Temp\ST_00000001.t mp not found

      The red sentence is the problem. It happens when I want to download or access to the data.

      Xiaochi

      Comment


      • #4
        Using the operating system's File Explorer or command prompt, see whether you can gain access to the directory C:\Users\JINXIA~1\AppData\Local\Temp\

        As an alternative, copy and paste the following code into Stata's command prompt and hit carriage return to run it:

        Code:
        version 12.1
        
        clear *
        set more off
        
        tempfile tmpfil0
        copy "http://api.worldbank.org//en/Countries/All?format=csv" `tmpfil0'
        
        erase `tmpfil0'
        
        * exit
        and see whether you get an error code consistent with denied access to the directory.

        Comment


        • #5
          Xiaochi,

          In addition to following Joseph's advice, you may want to consider contacting the authors of wbopendata to inform them of this problem. While it may not be their fault that you can't write to your TEMP directory, they should give you a more informative error if there is a problem. The command that copies from the web site to your temp file is preceded by capture which means that errors won't show up at that point. They don't check to see whether the copy command actually worked and then later on, the insheet command fails because the file can't be found. A more appropriate programming technique would be to check the error code produced by the copy command and give an informative message before aborting.

          I'm also a little concerned about the space between the "t" and the "m" in the file extension ("t mp"). Is that what was actually displayed when you ran the program, or did the space creep in when you copied the output to the Statalist post? (Or are my eyes just tricking me?). I don't know what would cause a temp file to have this name, but it could certainly cause a lot of problems.

          Regards,
          Joe

          Comment


          • #6
            To Joseph:

            Yes, I can get access to the directory of temp file, and when I run the codes, I got the same error:


            . copy "http://api.worldbank.org//en/Countries/All?format=csv" `tmpfil0'
            file http://api.worldbank.org//en/Countries/All?format=csv not found
            r(601);

            . erase `tmpfil0'
            file C:\Users\JINXIA~1\AppData\Local\Temp\ST_00000005.t mp not found
            r(601);

            Xiaochi

            Comment


            • #7
              To Joe:

              The "t mp" is because the space creep when I copied the codes. Can you have a look at the full codes? Thank you.

              ----------------------------------------------------------------------------------------------------------------------- begin _query ---
              - version 9.0
              - syntax [, LANGUAGE(string) COUNTRY(string) TOPICS(string) INDICATOR(string) YEAR(string) LONG CLEAR LATEST NOMETADATA ]
              - quietly {
              - if ("`language'" == "") {
              = if ("" == "") {
              - local language "en"
              - }
              - if ("`language'" != "") {
              = if ("en" != "") {
              - local language = word("`language'",1)
              = local language = word("en",1)
              - }
              - if ("`country'" != "") {
              = if ("chn - China" != "") {
              - local country1 = word("`country'",1)
              = local country1 = word("chn - China",1)
              - local t = substr("`country1'",-1,1 )
              = local t = substr("chn",-1,1 )
              - if ("`t'" == ";") {
              = if ("n" == ";") {
              local l = length("`country1'")
              local l = `l'-1
              local country1 = substr("`country'",1,`l')
              }
              - local q = subinstr("`country1'",";"," ",.)
              = local q = subinstr("chn",";"," ",.)
              - local q = wordcount("`q'")
              = local q = wordcount("chn")
              - if (`q'>1) & ("`indicator'" == "") {
              = if (1>1) & ("" == "") {
              noi di as err "Users can not select multiple countries without specifying the indicator of interest. Please try again."
              exit 198
              }
              - local parameter "Countries/`country1'"
              = local parameter "Countries/chn"
              - local id "indicatorname indicatorcode "
              - }
              - if ("`topics'" != "") {
              = if ("" != "") {
              local topics1 = word("`topics'",1)
              local parameter "Topics/`topics1'"
              local id " countryname countrycode indicatorname indicatorcode "
              }
              - if ("`indicator'" != "") {
              = if ("" != "") {
              local indicator1 = word("`indicator'",1)
              local indicator2 = subinstr("`indicator'","`indicator1'","",.)
              local indicator2 = trim(subinstr("`indicator2'","-","",.))
              if ("`indicator2'" == "") {
              local indicator2 "`indicator1'"
              }
              local year1 "date=`year'&"
              local parameter "Indicators/`indicator1'?`year1'"
              local id " countryname countrycode "
              }
              - if ("`country'" == "") & ("`topics'" == "") & ("`indicator'" == "") {
              = if ("chn - China" == "") & ("" == "") & ("" == "") {
              di as err "Users need to select either a country, a topic, or an indicator. Please try again."
              exit 198
              }
              - if ("`country'" != "") & ("`topics'" != "") & ("`indicator'" == "") {
              = if ("chn - China" != "") & ("" != "") & ("" == "") {
              di as err "Users can not select a country and a topic at the same time. Please try again."
              exit 198
              }
              - if ("`country'" == "") & ("`topics'" != "") & ("`indicator'" != "") {
              = if ("chn - China" == "") & ("" != "") & ("" != "") {
              di as err "Users can not select an indicator and a topic at the same time. Please try again."
              exit 198
              }
              - if ("`indicator'" == "") & ("`year'" != "") {
              = if ("" == "") & ("" != "") {
              di as err "year option can only be used for the selection of specific indicators. Please try again."
              exit 198
              }
              - if ("`indicator'" == "") & ("`latest'" != "") {
              = if ("" == "") & ("" != "") {
              di as err "latest option can only be used for the selection of specific indicators in the long format. Please try again."
              exit 198
              }
              - if ("`indicator'" != "") & ("`latest'" != "") & ("`long'" == "") {
              = if ("" != "") & ("" != "") & ("" == "") {
              di as err "latest option can only be used for the selection of specific indicators in the long format. Please try again."
              exit 198
              }
              - if ("`country'" == "") & ("`indicator'" != "") {
              = if ("chn - China" == "") & ("" != "") {
              local country2 "all"
              }
              - if ("`country'" != "") & ("`indicator'" != "") {
              = if ("chn - China" != "") & ("" != "") {
              local country2 "`country1'"
              }
              - tempfile temp
              - loc servername "http://api.worldbank.org/"
              - if (("`country'" != "") | ("`topics'" != "")) & ("`indicator'" == "") {
              = if (("chn - China" != "") | ("" != "")) & ("" == "") {
              - capture : copy "`servername'/`language'/`parameter'?format=csv" `temp'
              = capture : copy "http://api.worldbank.org//en/Countries/chn?format=csv" C:\Users\JINXIA~1\AppData\Local\Temp\ST_00000001.t mp
              - }
              - if ("`indicator'" != "") {
              = if ("" != "") {
              capture : copy "`servername'/`language'/countries/`country2'/`parameter'format=csv" `temp'
              }
              - insheet using `temp', `clear' name
              = insheet using C:\Users\JINXIA~1\AppData\Local\Temp\ST_00000001.t mp, clear name
              file C:\Users\JINXIA~1\AppData\Local\Temp\ST_00000001.t mp not found
              foreach var of varlist _all {
              local varname : variable label `var'
              if (real("`varname'") != .) {
              rename `var' yr`varname'
              local l1 "yr"
              local l2 "year"
              local l3 ""
              local l4 "lab var year Year"
              local t1 "year"
              }
              else {
              if match("`varname'","*Q*") == 1 {
              local tmp0 = subinstr("`varname'","Q","-",.)
              local tmp1 = tq(`tmp0')
              rename `var' q`tmp1'
              local l1 "q"
              local l2 "quarter"
              local l3 "format quarter %tq"
              local l4 "lab var quarter Quarter"
              local t1 "quarter"
              }
              }
              }
              return local period = "`l2'"
              drop v*
              if (("`long'" == "") & ("`country'" != "")) & ("`indicator'" == "") {
              local w1 = word("`country'",1)
              local w2 = trim(subinstr("`country'","`w1' - ","",.))
              gen str5 countrycode = upper("`w1'")
              gen str80 countryname = "`w2'"
              order countryname countrycode
              lab var countryname "Country Name"
              lab var countrycode "Country Code"
              }
              if ("`long'" == "") & ("`indicator'" != "") {
              local w1 = word("`indicator'",1)
              local w2 = trim(subinstr("`indicator' ","`w1' - ","",.))
              gen indicatorcode = "`w1'"
              gen indicatorname = "`w2'"
              order countryname countrycode indicatorname indicatorcode
              lab var indicatorname "Indicator Name"
              lab var indicatorcode "Indicator Code"
              }
              if (("`long'" != "") & ("`country'" != "")) & ("`indicator'" == "") {
              local w1 = word("`country'",1)
              local w2 = trim(subinstr("`country'","`w1' - ","",.))
              gen str5 countrycode = upper("`w1'")
              gen str80 countryname = "`w2'"
              order countryname countrycode
              lab var countryname "Country Name"
              lab var countrycode "Country Code"
              reshape long `l1' , i( countryname countrycode `id') j(`l2')
              `l3'
              `l4'
              rename `l1' value
              replace indicatorname = indicatorcode + " " + indicatorname
              encode indicatorname, gen(indic)
              drop indicatorname indicatorcode
              _pecats2 indic
              loc cat "`r(catvals)'"
              foreach i in `cat' {
              local t`i' : label indic `i'
              local k`i' = word("`t`i''", 1)
              local j`i' = trim(subinstr("`t`i''","`k`i''","",.))
              local n`i' = trim(lower(subinstr(word("`t`i''", 1),".","_",.)))
              }
              reshape wide value , i( countryname countrycode `l2') j( indic)
              foreach i in `cat' {
              rename value`i' `n`i''
              lab var `n`i'' "`j`i''"
              }
              `l3'
              `l4'
              }
              if ("`long'" != "") & ("`indicator'" != "") {
              local w1 = word("`indicator'",1)
              local w2 = trim(subinstr("`indicator' ","`w1' - ","",.))
              gen indicatorcode = "`w1'"
              gen indicatorname = "`w2'"
              order countryname countrycode indicatorname indicatorcode
              lab var indicatorname "Indicator Name"
              lab var indicatorcode "Indicator Code"
              reshape long `l1' , i( `id') j(`l2')
              local name = trim(lower(subinstr(word("`indicator'",1),".","_", .)))
              rename `l1' `name'
              label var `name' "`indicator2'"
              `l3'
              `l4'
              if ("`latest'" != "") {
              keep if `name' != .
              sort countryname countrycode `l2'
              bysort countryname countrycode : keep if _n==_N
              }
              drop indicatorname indicatorcode
              }
              if ("`long'" != "") & ("`topics'" != "") {
              reshape long `l1' , i( `id') j(`l2')
              `l3'
              `l4'
              rename `l1' value
              replace indicatorname = indicatorcode + " " + indicatorname
              encode indicatorname, gen(indic)
              drop indicatorname indicatorcode
              _pecats2 indic
              loc cat "`r(catvals)'"
              foreach i in `cat' {
              local t`i' : label indic `i'
              local k`i' = word("`t`i''", 1)
              local j`i' = trim(subinstr("`t`i''","`k`i''","",.))
              local n`i' = trim(lower(subinstr(word("`t`i''", 1),".","_",.)))
              }
              reshape wide value , i( countryname countrycode `l2') j( indic)
              foreach i in `cat' {
              rename value`i' `n`i''
              lab var `n`i'' "`j`i''"
              }
              `l3'
              `l4'
              }
              }
              ------------------------------------------------------------------------------------------------------------------------- end _query ---
              local time "`r(time)'"
              if ("`nometadata'" == "") & ("`indicator'" != ""){
              noi _query_metadata , indicator("``i''")
              }
              local w1 = word("`indicator'",1)
              return local varname1 = trim(lower(subinstr(word("`w1'",1),".","_",.)))
              return local indicator1 "`w1'"
              return local country1 "`country'"
              return local topics1 "`topics'"
              return local year1 "`year'"
              return local source1 "`r(source)'"
              return local varlabel1 "`r(varlabel)'"
              return local time1 "`time'"
              local name = trim(lower(subinstr(word("`w1'",1),".","_",.)))
              }
              return local indicator "`indicator'"
              local f = `f'-1
              if (`f' != 0) {
              if ("`long'" != "") {
              use `file1'
              forvalues i = 2(1)`f' {
              merge countrycode year using `file`i''
              drop _merge
              sort countrycode `time'
              }
              }
              if ("`long'" == "") {
              use `file1'
              forvalues i = 2(1)`f' {
              append using `file`i''
              }
              }
              }
              if ("`latest'" != "") & ("`long'" != "") {
              tempvar tmp
              egen `tmp' = rowmiss(`name')
              keep if `tmp' == 0
              sort countryname countrycode `time'
              bysort countryname countrycode : keep if _n==_N
              }
              }
              ----------------------------------------------------------------------------------------------------------------------- end wbopendata ---
              r(601);


              Xiaochi

              Comment


              • #8
                If you click on the data-source URL, itself, you get an error message in XML that indicates that comma-separated value datasets aren't available from the API. The formats that are available seem to be listed here.

                Comment


                • #9
                  Joseph:

                  All my wbopendata codes have this URL. Maybe I should contact with the team of wbopendata for this problem?

                  Xiaochi

                  Comment


                  • #10
                    That might be a good place to start, yes. When you do, you might want to relay what Joe Canner mentioned, too.

                    Comment


                    • #11
                      Xiachoi, you put a very long section of code in your posting. To my mind the readability of your posting is much improved if you use the advanced editor options of the Forum software when posting Stata code segments:

                      Find the "toggle advanced editor" icon top right of the editor window, mark the sections containing your Stata code, and click on the # - icon to enclose the code with the respective BBCode commands. To see how the posting will look like to the reader you can use the "preview" button to the bottom right of the editor window. Long code segments will then be shown within a scrollable window.

                      Comment


                      • #12
                        Thank you all.

                        Comment


                        • #13
                          I am having the same issue with wbopendata. Were you able to make it work? I tried a lot of things but I still receive this error message of a missing TEMP file. Do you think that this is because I am using stata 12?
                          Thanks a lot! Paula

                          Comment


                          • #14
                            I am having the same problem with Stata 12 on a mac. did it ever get resolved?

                            Comment


                            • #15
                              One thing I noticed was that your URL seems to be mal-formed: http://api.worldbank.org//en/Countries/chn?format=csv has two forward slashes in the middle of it, which is not normal, and as far as I know, would cause any webserver to barf. Try http://api.worldbank.org/en/Countries/chn?format=csv (removed the second slash before "/en/")

                              rAlso, if you remove the "capture" commands throughout, it will potentially throw a meaningful error earlier on.
                              Last edited by ben earnhart; 05 Sep 2014, 09:59. Reason: mentioned removing "capture"

                              Comment

                              Working...
                              X