3
$\begingroup$

I have an income distribution dataset which I am attempting to manipulate in Stata (or SAS).

I need to come up with a table listing the number of households earning between one income level and another. The income levels are regularly spaced, say at $10,000 intervals for example.

In other words, for $i=30,000$, I want to know the number of households $H_i$ receiving between 20,000 and 30,000. And I want to know this for each i, at 10,000 dollar intervals, from 10,000 up to oh let's say 280,000.

$H_i=\int_{i-10000}^{i}f(x)\: dx$

$(0 < i\leq280000)$

(Where f(x) is the underlying density function representing households plotted along the y-axis, and x is income level, plotted along the x-axis. The distribution will have the skewed (lognormal-like) shape typical of income distributions.)

Does anyone know the Stata (or SAS) command that would give me this info? In Stata I can get the income at each percentile of the population using the "centile" command, but this doesn't quite give me what I want.

Thanks

$\endgroup$

3 Answers 3

2
$\begingroup$

In Stata, assuming each case is a household,

gen i = autocode(x, 28, 0, 280000)
tab i

If cases represent multiple households, use weights with the tab command.

The help for autocode can be found under functions|programming functions.

$\endgroup$
8
  • $\begingroup$ @whuber --Thanks! However the "tab i" is not doing the trick. I mean it's not summing the casenumbers (represented along the y axis) between income levels $i$ and $i-1$ along the x axis. (Casenumbers are households, so no need for weighting). $\endgroup$
    – ben
    Commented Sep 4, 2011 at 5:15
  • $\begingroup$ @whuber Aha. The following command gives me the number of households (case numbers) between two income levels: count if dpi<30000 & dpi>20000. But this will be tedious to do from 0 to 280,000 at intervals of 10,000. Is there any way to do this more quickly? $\endgroup$
    – ben
    Commented Sep 4, 2011 at 7:48
  • 1
    $\begingroup$ @whuber. Via the second argument of the autocode function you have to specify the number of intervals you want to create, rather than the width of the intervals. Thus, here you would have to type gen i = autocode(x, 28, 0, 280000) or gen i = autocode(x, 27, 10000, 280000), depending on whether you start at 0 or 10000. $\endgroup$
    – user5644
    Commented Sep 5, 2011 at 12:08
  • $\begingroup$ @lejohn Thank you! I tested this code but copied the command incorrectly. I'll edit the reply to fix the mistake. $\endgroup$
    – whuber
    Commented Sep 6, 2011 at 15:06
  • $\begingroup$ @Ben what's the matter with tab i? It works for me. The output gives frequencies (those are the counts you want), percent, and cumulative percent. If you need more than that, or you need to post-process the output, use collapse or contract. $\endgroup$
    – whuber
    Commented Sep 6, 2011 at 15:08
2
$\begingroup$

In Stata, you can achieve this as follows:

clear
set seed 99
set obs 1000
gen inc = 10000 * exp(invnorm(uniform()))
gen lb = floor(inc/10000) * 10000
tabulate lb

This code creates left-bounded intervals, i.e. including the lower bound, but excluding the upper bound.

If you prefer the count approach, you can use the following code:

forvalues n = 0(10000)280000 {
    count if inrange(inc, `n', `n' + 10000)
}

Note that the inrange function refers to left-bounded intervals too.

If you need a table to be inserted in a document, you can add the following lines:

collapse (count) N = inc, by(lb)
gen interval = "[" + string(lb) + ";" + string(lb + 10000) + ")" 
list interval N, sep(0) noobs
$\endgroup$
1
$\begingroup$

In SAS something like this could work:

data new;
 set old;
 inccat = floor(income/10000);
run;

proc freq data = new;
 table inccat;
run;
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.