Dear all,
I have the following task. I want to estimate the effect of winning a particular auction on a firm's growth. For each auction, I observe the winner and second firm which I plan to use as a counterfactual. I build an example of how it may look. I have firmid which is unique for each firm, contractid which indicates a particular auction, year, rating which shows who was the first and second for an auction, artificial variable yprofit that shows firm's profit, d1 is a dummy = 1 if it is winner. Below is an example of a dataset.
I tried to implement it in this way:

bysort contractid: gen d1 = 1 if rating == 1
replace d1 = 0 if d1 ==.
replace d1 =. if rating ==.
xtset contractid
reg yprofit d1

I also tried in this way:

bysort contractid: reg yprofit d1


Actually, I have doubts about the correctness. Could you please suggest me the right way how to proceed with it?

firmid contractid year rating yprofit d1
1 111 2010 1 1000 1
2 111 2010 2 800 0
3 222 2011 1 1300 1
1 222 2011 2 1100 0
2 333 2012 2 1000 0
3 333 2012 1 1400 1
1 444 2013 2 1300 0
2 444 2013 1 1100 1
2 . 2011 . 900 .
3 . 2013 . 1500 .
3 . 2010 . 1200 .
1 . 2012 . 1200 .