Announcement

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

  • ineqdeco - Theil index

    Hello!

    I am working on regional income disparities and for that I wanted to calculate the Theil Index (and the Wiliamsons coefficient if it is possible). My income data is by region and time (from 2004 to 2023). I would like to get the index for each year, to see what the trend is in the last 20 years. I also have the population of each year by region.

    I have been trying to run the following command but something seems to not be working well.

    ineqdeco adjusted_regional_income_2004 [fw=pop2004], by(region)

    I was planning on doing this for every year, but I get the error of "no observations". Do you perhaps know why?

    Also, is there a faster way to get the index for every year?

    Thank you so much for any help or advise you can provide.

  • #2
    Why you get zero obbservations is a mystery that we, who do not have access to your data, cannot solive. What if you try -ineqdec0- (also SSC instead) -- for Gini and half CV-squared? If that works, the issue is something to do with zero incomes

    Once you've solved that issue, then should be looking to save the estimated inequality indices into new variables. Pseudo-code something like the following

    Code:
    gen theil = .
    gen mld = .
    
    forvalues yr = 1/T {
           forvalues r = 1/R  {
      
                 ineqdeco  adjusted_regional_income [fw = pop] if region == `r' & year == `yr'
                 replace theil = r(ge1) if region == `r' & year == `yr'
                 replace mld = r(ge0) if region == `r' & year == `yr'
          }
    }
    I'm assuming you've converted your data into long format, so that you have observations identified by region-year combinations, hence no need for year-suffixes. I've assumed that year and region are numeric variables (you'll know what T and R are). If not consecutive integers, look into using -levelsof- to put the values of region and of year and use -foreach- (looping over local macros) rather than -forvalues-

    The pseudo code also indicates how its straightforward to get additional indices, not only Theil.

    Comment


    • #3
      Hi Stephen,

      Thank you very much for your help! It works now! The first code works now! (ineqdeco adjusted_regional_income_2004 [fw=pop2004], by(region))

      However I still got problems when I convert the data into long format and try to run your code. I get again the no observations error. My year and region variables are numeric and consecutive integers. Year goes from 1-20 and region 1-24. Also, why do I no longer have to include the byoption? I am only interested in the between region diparities and do not have data for the within comparison.

      Thank you again

      Comment


      • #4
        I have no idea why your problem persists (and you continue not to show us a data snippet -- see Forum FAQ on how to do this). You could use the by option of course. (I was simply trying to show how you could put the output into variables). I do not have access to Stata for the rest of the week, btw

        Comment

        Working...
        X