I have micro data and I am running a regression of wages on industry dummies.
My regression output then includes a coefficient for each industry, which I want to save as a new variable named wd (wage differential).
The code below exemplifies what I want to do, but in reality I have hundreds of industries and almost 30 years.
How I could make a loop that does this efficiently?
reg lnwage i.industry if year == 2002
gen wd = 0
replace wd = 0 if industry==1 & year==2002
replace wd = _b[2.industry] if industry==2 & year==2002
replace wd = _b[3.industry] if industry==3 & year==2002
replace wd = _b[4.industry] if industry==4 & year==2002
replace wd = _b[5.industry] if industry==5 & year==2002
replace wd = _b[6.industry] if industry==6 & year==2002
replace wd = _b[7.industry] if industry==7 & year==2002
replace wd = _b[8.industry] if industry==8 & year==2002
replace wd = _b[9.industry] if industry==9 & year==2002
replace wd = _b[10.industry] if industry==10 & year==2002
replace wd = _b[11.industry] if industry==11 & year==2002
replace wd = _b[12.industry] if industry==12 & year==2002
replace wd = _b[13.industry] if industry==13 & year==2002
replace wd = _b[14.industry] if industry==14 & year==2002
replace wd = _b[15.industry] if industry==15 & year==2002