Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: generating a variable


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: generating a variable
Date   Tue, 13 Nov 2012 12:13:55 +0100

On Tue, Nov 13, 2012 at 11:58 AM, Rubil Ivica wrote:
> problem. I have a dataset with a number of individual-level observations. For each person, I have an identifier of the region (region_id) within (s)he lives in. I need to generate the following measure of upward relative income deprivation (rel_depr_up) for each person: the sum of differences between the person's income and incomes of all people with HIGHER income in the same region, divided by the total number of people in the region. Another measure I need is a measure of downward relative income satisfaction: the sum of differences between the person's income and incomes of all people with LOWER income in the same region, divided by the total number of people in the region.

*-------------------------- begin example -----------------------------------
sysuse nlsw88, clear
// industry plays the role of region

bys industry (wage) : gen rel_sat_down = ( sum(wage) - wage ) / (_n -1)
gen sortorder = -wage
bys industry (sortorder) : gen rel_depr_up = ( sum(wage) - wage ) / (_n - 1)

// see the result
list industry wage rel_depr_up rel_sat_down in 1/20, sepby(industry)
*-------------------------- end example -----------------------------------

Hope this helps,
Maarten

---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index