File size: 5,049 Bytes
2a8276b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160


clear all
set more off
set maxvar 10000

*Set path
***

*cd ---- specify path to \data_replication\psid\


cd raw_data

*Import data for individuals
do IND2011ER.do

*Generate unique id
*Last three digits are the person number
*ER30001-1968 Family id
*ER30002-Person number
gen hid=ER30001*1000+ER30002

cd ..
cd proc_data
save temp_master.dta,replace

****************************************
*Join with data after taxsim correction 
*in order to assign the unique id to the
*household head
****************************************
***
* IMPORTANT !!! paste files from "our_proc" subfolder into the "proc_data" folder if you didn't manage to get taxsim9 to run on your computer 
***

*1999
use temp_master.dta,clear
drop if ER33503!=10    //keep only heads in that year
drop if ER33502!=1     //keep only if head is still within family unit
rename ER33501 fam_ID_year
joinby fam_ID_year using temp1999.dta, unmatched(both)
drop if _merge!=3
drop _merge
drop if age_head!=ER33504  //drop obs. that are inconsistent about the age of head
drop ER*
save p1999.dta, replace
*2001
use temp_master.dta,clear
drop if ER33603!=10    //keep only heads in that year
drop if ER33602!=1     //keep only if head is still within family unit
rename ER33601 fam_ID_year
joinby fam_ID_year using temp2001.dta, unmatched(both)
drop if _merge!=3
drop _merge
drop if age_head!=ER33604  //drop obs. that are inconsistent about the age of head
drop if ER33608!=0        //drop if head has moved in/out (splitoffs)
drop ER*
save p2001.dta, replace
*2003
use temp_master.dta,clear
drop if ER33703!=10    //keep only heads in that year
drop if ER33702!=1     //keep only if head is still within family unit
rename ER33701 fam_ID_year
joinby fam_ID_year using temp2003.dta, unmatched(both)
drop if _merge!=3
drop _merge
drop if age_head!=ER33704  //drop obs. that are inconsistent about the age of head
drop if ER33708!=0        //drop if head has moved in/out (splitoffs)
drop ER*
save p2003.dta, replace
*2005
use temp_master.dta,clear
drop if ER33803!=10    //keep only heads in that year
drop if ER33802!=1     //keep only if head is still within family unit
rename ER33801 fam_ID_year
joinby fam_ID_year using temp2005.dta, unmatched(both)
drop if _merge!=3
drop _merge
drop if age_head!=ER33804  //drop obs. that are inconsistent about the age of head
drop if ER33808!=0        //drop if head has moved in/out (splitoffs)
drop ER*
save p2005.dta, replace
*2007
use temp_master.dta,clear
drop if ER33903!=10    //keep only heads in that year
drop if ER33902!=1     //keep only if head is still within family unit
rename ER33901 fam_ID_year
joinby fam_ID_year using temp2007.dta, unmatched(both)
drop if _merge!=3
drop _merge
drop if age_head!=ER33904  //drop obs. that are inconsistent about the age of head
drop if ER33908!=0        //drop if head has moved in/out (splitoffs)
drop ER*
save p2007.dta, replace
*2009
use temp_master.dta,clear
drop if ER34003!=10    //keep only heads in that year
drop if ER34002!=1     //keep only if head is still within family unit
rename ER34001 fam_ID_year
joinby fam_ID_year using temp2009.dta, unmatched(both)
drop if _merge!=3
drop _merge
drop if age_head!=ER34004  //drop obs. that are inconsistent about the age of head
drop if ER34008!=0        //drop if head has moved in/out (splitoffs)
drop ER*
save p2009.dta, replace
*2011
use temp_master.dta,clear
drop if ER34103!=10    //keep only heads in that year
drop if ER34102!=1     //keep only if head is still within family unit
rename ER34101 fam_ID_year
joinby fam_ID_year using temp2011.dta, unmatched(both)
drop if _merge!=3
drop _merge
drop if age_head!=ER34104  //drop obs. that are inconsistent about the age of head
drop if ER34108!=0        //drop if head has moved in/out (splitoffs)
drop ER*
save p2011.dta, replace


****************************************
*Create panel
****************************************
*Adjust the names of the variables
forval x=1999(2)2011{
use p`x'.dta, clear
ren aftertax_income_defl_equiv inc`x'
ren age_head age`x'
ren ed_head edu`x'
ren marital_status_head mstat`x'
ren fam_ID_year fam_ID`x'
ren size_fam size_fam`x'
drop fam_ID_1968 year_survey  //drop variables that are not useful
save pk`x'.dta,replace
}

*Join datasets to form a panel
use pk1999.dta, clear
forval x=2001(2)2011{
joinby hid using pk`x'.dta, unmatched(both)
drop if _merge!=3
drop _merge
local i=`x'-2
di "`i'"
gen b=age`x'-age`i'
tab b  
drop if b!=2 & b!=1 & b!=3   // drop people that are inconsistent about their age (1/2/3 are consistent due to the differences in month of interview)
drop b
gen a=edu`x'-edu`i'
tab a 
drop if a<0     // drop people that are inconsistent about their education (to adjust for any errors, see 2009 family codebook release info)
drop a
}

*Reshape the data for better use
reshape long inc age edu mstat fam_ID size_fam, i(hid) j(year) 

save for_reg.dta, replace