Announcement

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

  • Weighted mean for each year, by regions in a panel data

    I have a panel dataset of 51 countries for 19 years. For each of the panels, it is subdivided into five regions. I wish to calculate the weighted means of the BIT variable by year across the five regions. A snapshot of my dataset is attached that shows the weights, BITS(variable of interest) and region.
    country year region weight bits
    Algeria 2000 NOA 0.095238 29
    Algeria 2001 NOA 0.095238 33
    Algeria 2002 NOA 0.095238 35
    Algeria 2003 NOA 0.095238 38
    Algeria 2004 NOA 0.095238 40
    Algeria 2005 NOA 0.095238 41
    Benin 2000 WAC 0.091667 3
    Benin 2001 WAC 0.091667 11
    Benin 2002 WAC 0.091667 11
    Benin 2003 WAC 0.091667 11
    Benin 2004 WAC 0.091667 14
    Benin 2005 WAC 0.091667 14
    Botswana 2000 SADC 0.109091 4
    Botswana 2001 SADC 0.109091 4
    Botswana 2002 SADC 0.109091 7
    Botswana 2003 SADC 0.109091 7
    Botswana 2004 SADC 0.109091 8
    Botswana 2005 SADC 0.109091 9
    Burkina Faso 2000 WAC 0.05 12
    Burkina Faso 2001 WAC 0.05 12
    Burkina Faso 2002 WAC 0.05 13
    Burkina Faso 2003 WAC 0.05 14
    Burkina Faso 2004 WAC 0.05 14
    Burkina Faso 2005 WAC 0.05 14
    Burundi 2000 CAC 0.155556 5
    Burundi 2001 CAC 0.155556 5
    Burundi 2002 CAC 0.155556 5
    Burundi 2003 CAC 0.155556 5
    Burundi 2004 CAC 0.155556 5
    Burundi 2005 CAC 0.155556 5
    Chad 2000 CAC 0.022222 5
    Chad 2001 CAC 0.022222 9
    Chad 2002 CAC 0.022222 9
    Chad 2003 CAC 0.022222 9
    Chad 2004 CAC 0.022222 11
    Chad 2005 CAC 0.022222 11
    Comoros 2000 EAC 0.120879 1
    Comoros 2001 EAC 0.120879 6
    Comoros 2002 EAC 0.120879 6
    Comoros 2003 EAC 0.120879 6
    Comoros 2004 EAC 0.120879 6
    Comoros 2005 EAC 0.120879 6
    Egypt 2000 NOA 0.238095 98
    Egypt 2001 NOA 0.238095 102
    Egypt 2002 NOA 0.238095 104
    Egypt 2003 NOA 0.238095 105
    Egypt 2004 NOA 0.238095 107
    Egypt 2005 NOA 0.238095 109
    Eswatini 2000 SADC 0.145455 5
    Eswatini 2001 SADC 0.145455 5
    Eswatini 2002 SADC 0.145455 5
    Eswatini 2003 SADC 0.145455 5
    Eswatini 2004 SADC 0.145455 5
    Eswatini 2005 SADC 0.145455 5
    Ethiopia 2000 EAC 0.043956 10
    Ethiopia 2001 EAC 0.043956 11
    Ethiopia 2002 EAC 0.043956 12
    Ethiopia 2003 EAC 0.043956 17
    Ethiopia 2004 EAC 0.043956 22
    Ethiopia 2005 EAC 0.043956 22
    I sincerely appreciate any advice on how to proceed.

    Note:

    There is a similar post here is yet to receive any response.

  • #2
    Code:
    by region year, sort: egen numerator = total(weight*bits)
    by region year: egen denominator = total(weight)
    gen weighted_bits_mean = numerator/denominator
    In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment


    • #3
      Clyde Schechter, Thank you and your recommendation well noted

      Comment

      Working...
      X