Match firms by sic code and ipo date in state

I am currently researching the US Ipo market and due to stata being completely new for me I encountered the following problem:

I have two data sets in which each the variables company name, ipo date and sic code are given. one data set is called: IPO firms. The other one is called peers. What I need to find out is how to select for each firm of the ipo firm - dataset a comparable firm in the peer - dataset. These firms need to be matched by having the same sic code and the the ipo date of the peer - data set should be three years before the ipo date of the ipo firm ) dataset

I hope someone could help me with this. Ive been searching the internet for a while but i couldn't find a solution


I would do this using -merge-. You may need to create a new variable in one or both of the datasets to incorporate the 3-year offset, then -merge- on sic and the year.