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: Controlling for median via industry


From   Jorge Eduardo Pérez Pérez <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Controlling for median via industry
Date   Wed, 12 Feb 2014 10:45:56 -0500

* Get a dataset of firms
clear
webuse abdata
bys id: keep if _n==1
keep id ind year wage
* I am going to give some variation to the years by adding a random
integer, 1 to 10
set seed 100
replace year=year+1+int((10-1+1)*runiform())
sort ind id
* Save this original database
tempfile all
save `all'

* Create median variable to be filled
gen median=.
* Loop over firms
levelsof id, local(ids)
foreach x in `ids' {
preserve
* Keep the firm
keep if id==`x'
ren year yearo
keep id yearo ind
* Merge with firms of same industry
merge 1:n ind using `all', keepusing(year wage) keep(match)
* Keep only the older ones
keep if year>=yearo
* Calculate median only if group has 15 firms or more
count
if r(N)>=15 {
_pctile wage, p(50)
glo median=r(r1)
}
else glo median=.
restore
* Replace empty median variable with calculated median
replace median=${median} if id==`x'
}
--------------------------------------------
Jorge Eduardo Pérez Pérez
Graduate Student
Department of Economics
Brown University


On Wed, Feb 12, 2014 at 4:09 AM, Peter Miller <[email protected]> wrote:
> Dear Stata-Community,
>
> I've a problem, which I can't figure out for quite some while. Maybe one of you has an idea how to solve this problem.
>
> Here is the setting: I've a large sample of firms each identified with an ID, Date, Industry and Earnings for example.  For each firm now, I have to control the earnings by the median earnings of the particular industry the firm belongs to.
>
> For example: Firm X belongs to Industry Y then it should be something like this:
> Adjusted earnings = Earnings firm X - Median of Industry Y
>
> In addition, the groups that build the median should have at least 15 firms,  are not allowed to be older than 5 years compared to firm X, and they are not allowed to be younger, i.e. they should not exist before firm X.
>
> I struggle with it for quite some while. Any help would be much appreciated!!!
>
> Best regards,
> Peter
>
> *
> *   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/

*
*   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