Hey Statalists,
i wanto to find 6 matches for each of my treated observations (companies). Moreover I need to fix for year and industry. If mahapick finds less than 6 matches, I would like to run mahapick again for all missing matches and fix for the next close industry (industry code +1) while keeping the results of the non-missing previous mahapicks.
That means after the frist run of mahapick my observations might be in different stages regarding how many matches they have. So far, I failed to create the right code for repeating the mahapick this way.
Below you´ll find dataex and the code so far. If you have any idea how to solve my problem please help me out!
i wanto to find 6 matches for each of my treated observations (companies). Moreover I need to fix for year and industry. If mahapick finds less than 6 matches, I would like to run mahapick again for all missing matches and fix for the next close industry (industry code +1) while keeping the results of the non-missing previous mahapicks.
That means after the frist run of mahapick my observations might be in different stages regarding how many matches they have. So far, I failed to create the right code for repeating the mahapick this way.
Below you´ll find dataex and the code so far. If you have any idea how to solve my problem please help me out!
Code:
clear
input byte(id pair_id) int year byte(treat industry) int assets float bm_ratio
1 1 2015 1 10 100 .1
1 2 2016 1 10 110 .11
1 3 2017 1 10 120 .12
1 4 2018 1 10 130 .13
1 5 2019 1 10 140 .14
2 6 2015 1 20 200 .2
2 7 2016 1 20 210 .21
2 8 2017 1 20 220 .22
2 9 2018 1 20 230 .23
2 10 2019 1 20 240 .24
1 . 2015 0 10 100 .1
1 . 2016 0 10 110 .11
1 . 2017 0 10 120 .12
1 . 2018 0 10 130 .13
1 . 2019 0 10 140 .14
2 . 2015 0 20 200 .2
2 . 2016 0 20 210 .21
2 . 2017 0 20 220 .22
2 . 2018 0 20 230 .23
2 . 2019 0 20 240 .24
3 . 2015 0 10 105 .98
3 . 2016 0 10 115 .101
3 . 2017 0 10 125 .12
3 . 2018 0 10 135 .15
3 . 2019 0 10 145 .12
4 . 2015 0 20 205 .202
4 . 2016 0 20 215 .203
4 . 2017 0 20 225 .23
4 . 2018 0 20 235 .21
4 . 2019 0 20 245 .23
5 . 2015 0 10 130 .111111
5 . 2016 0 10 120 .1099999
5 . 2017 0 10 140 .132222
5 . 2018 0 10 180 .102222
5 . 2019 0 10 150 .12
6 . 2015 0 20 290 .23
6 . 2016 0 20 250 .23
6 . 2017 0 20 340 .24
6 . 2018 0 20 240 .25
6 . 2019 0 20 250 .24
7 . 2015 0 10 90 .13
7 . 2016 0 10 105 .14
7 . 2017 0 10 80 .14
7 . 2018 0 10 90 .15
7 . 2019 0 10 110 .15
8 . 2015 0 20 190 .24
8 . 2016 0 20 170 .24
8 . 2017 0 20 200 .245555
8 . 2018 0 20 205 .23
8 . 2019 0 20 206 .243333
9 . 2015 0 10 98 .09
9 . 2016 0 10 101 .093
9 . 2017 0 10 100 .096
9 . 2018 0 10 104 .098
9 . 2019 0 10 105 .104
10 . 2015 0 20 197 .08
10 . 2016 0 20 199 .089
10 . 2017 0 20 201 .092
10 . 2018 0 20 200 .095
10 . 2019 0 20 208 .099
11 . 2015 0 14 101 .11
11 . 2016 0 14 102 .12
11 . 2017 0 14 103 .13444
11 . 2018 0 14 102 .135666
11 . 2019 0 14 104 .147
12 . 2015 0 21 206 .23
12 . 2016 0 21 218 .23
12 . 2017 0 21 198 .235
12 . 2018 0 21 212 .237
12 . 2019 0 21 220 .239
13 . 2015 0 12 130 .1134
13 . 2016 0 12 128 .1139
13 . 2017 0 12 134 .1142
13 . 2018 0 12 138 .1134
13 . 2019 0 12 140 .1156
14 . 2015 0 22 230 .212
14 . 2016 0 22 228 .219
14 . 2017 0 22 220 .221
14 . 2018 0 22 231 .229
14 . 2019 0 22 235 .24
end
gen match_id_1 = .
gen match_id_2 = .
gen match_id_3 = .
gen match_id_4 = .
gen match_id_5 = .
gen match_id_6 = .
gen match_industry = industry
gen start_missing = 0
recast float id
mahapick assets bm_ratio, idvar(id) pickids(match_id_1 match_id_2 match_id_3 match_id_4 match_id_5 match_id_6) treated(treat) matchon(year industry)
foreach x in start_missing {
replace start_missing = cond(match_id_1==.,1,cond(match_id_2==.,2,cond(match_id_3==.,3,cond(match_id_4==.,4,cond(match_id_5==.,5,cond(match_id_6==.,6,0)))))) if treat == 1
replace match_industry = match_industry+1 if `x' >0 & treat == 1
mahapick assets bm_ratio, idvar(id) pickids(match_id_`x' UNTIL match_id_6) treated(treat) matchon(year match_industry) if `x' >0
}
