Dear All, I find this question here. The data set is
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte stkcd str5 year str8 BusinessInstitutionID byte want
4 "2011"  "10515981" .
4 "2012 " "10515981" 1
4 "2013 " "10515981" 1
4 "2013 " "10513314" .
4 "2014 " "10402864" .
4 "2014"  "10515981" .
4 "2014 " "10513314" 1
4 "2015 " "10516931" .
4 "2015"  "10514921" .
4 "2015"  "10515981" 1
4 "2015"  "10513314" 1
4 "2016"  "10516535" .
4 "2016"  "10519103" .
4 "2016"  "10516931" 1
4 "2016"  "10402864" .
4 "2016"  "10515981" 1
4 "2017 " "10520158" .
4 "2017"  "10519103" 1
4 "2017"  "10402864" 1
4 "2017"  "10513235" .
4 "2017 " "10520422" .
end
For each stkcd and each year, I'd like to identify whether `BusinessInstitutionID' has appeared in the previous year. If yes, return 1, otherwise missing data (zero is also fine). The variable `want' is the desired outcome. Thanks.