Announcement

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

  • Missing variables when downloading with wbopendata

    Hi all, I am trying to re-download the complete WDI dataset, so as to have data from more recent years. I had this issue last time I did this, but it is much worse this time. Obvious variables such as GDP, etc, are missing, which seems obviously wrong. To download I am downloading all indicators, for all countries, for all years, in a loop, using the following code. I later merge them all together.

    Code:
    forvalues i=1/21 {
        clear all
        wbopendata, language(en - English) country() topics(`i') indicator() long
        gen topics = `i'
        label var topics "World Development Indicator topic area"
        save "data\topic_`i'_2019.dta", replace
    }
    
    forvalues i=1/21 {
        if `i'==1 {
            local j = (`i'+1)
            use "data\test\topic_`i'_19.dta"
            merge 1:1 countryname year using "data\test\topic_`j'.dta"
            drop _merge
            save "data\test\wdi_1_21_2019.dta", replace    
        }
        }
    Does anybody have a better suggestion?!!

  • #2

    wbopendata is from SSC, as you are asked to explain (refer to the FAQs). I do not use the command but your statement is not clear.

    Obvious variables such as GDP, etc, are missing, which seems obviously wrong.
    It is common to have missing data for macroeconomic variables, especially if you are considering some years into the past. However, if you are finding that GDP figures are missing in recent years for a number of countries, then go into the World Bank Development Indicators (WDI) database and download these data sets. I have done that quite a few times and it is no hassle.

    Comment


    • #3
      How do you suggest doing that ("go into the World Bank Development Indicators (WDI) database and download these data sets")? My code above downloads all 21 topics from the WDI, and still I am finding a huge amount of macro variables to be missing. Thank you so much for your response.

      Comment


      • #4
        In the following code from post #1
        Code:
        forvalues i=1/21 {
            if `i'==1 {
              local j = (`i'+1)
                use "data\test\topic_`i'_19.dta"
                merge 1:1 countryname year using "data\test\topic_`j'.dta"
                drop _merge
                save "data\test\wdi_1_21_2019.dta", replace    
            }
            }
        the code I have highlighted in red is executed exactly one time, when `i' is 1 and `j 'is 2. So 19 of your 21 indicators are missing.

        Perhaps you wanted something more like the following.
        Code:
        forvalues i=1/21 {
            clear all
            wbopendata, language(en - English) country() topics(`i') indicator() long
            gen topics = `i'
            label var topics "World Development Indicator topic area"
            save "data\topic_`i'_2019.dta", replace
        }
        
        use "data\topic_1_2019.dta"
        forvalues j=2/21 {
            merge 1:1 countryname year using "data\topic_`j'_2019.dta"
            drop _merge
            save "data\wdi_1_21_2019.dta", replace    
            }

        Comment


        • #5
          Aw, yes. What a silly error on my part. Your code works perfectly. A million thanks!!!!

          Comment


          • #6
            How do you suggest doing that ("go into the World Bank Development Indicators (WDI) database and download these data sets")?
            I do not use the command, so I do not know how it works. Hopefully, William's suggestion does it for you. If not, here is the link to directly access the WDI database.

            https://databank.worldbank.org/repor...nt-indicators#

            Comment

            Working...
            X