Announcement

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

  • how to use population as fweight in xtreg?

    Dear all,

    I am now using worldbank data to see how GDP per capita affects infant motality from 1990-2015, and I want to take total population of each country as fweight when performing panel data analysis. But stata does not allow me to use time-variant weights in xtreg, what should I do in order to consider the populaiton size of different countries.
    Below is my stata code

    wbopendata, indicator(SP.DYN.IMRT.IN ; NY.GDP.PCAP.PP.KD ; SP.POP.TOTL) long clear
    rename sp_dyn_imrt_in infantmortality
    rename ny_gdp_pcap_pp_kd gdppc
    rename sp_pop_totl poptotl

    encode countrycode, gen(country)
    xtset country year
    xtdes
    xtreg infantmortality gdppc [fweight=poptotl], fe
    then I get the result shown below, it seems I should take population fixed across years. what should I to do next?

    . xtreg infantmortality gdppc [fweight=poptotl], fe
    weight must be constant within country
    r(199);


    All the best,

    Zhicheng

  • #2
    Well, you are actually just lucky that Stata wouldn't let you do this, because it's a wrong use of -fweight-s. Stata's -fweight-s are used to replicate an observation a given number of times. So, if you had, say 10 observations in your data set with all of the same values on the regression variables, you could replace that with a single observation and use an -fweight- of 10 instead. But that is not what you have at all. You have country level data and you are trying to do an analysis in which each observation "stands for" a certain number of people. But you do not actually have that number of identical observations.

    So what you need here are -aweights-. Unfortunately, -xtreg- doesn't support -aweights- at all. But, since you are looking for a linear regression model, you can get around that by emulating -xtreg, fe- by -regress- and including indicator variables for the countries. So what you should do looks more or less like this:

    Code:
    regress infantmoratlity gdppc i.country [aweight = poptot]

    Comment

    Working...
    X