HTML Code:
clear
input str10 company_name str3 country int year
"3Mcompany"  "USA" 2002
"3Mcompany"  "USA" 2002
"3Mcompany"  "USA" 2003
"3Mcompany"  "USA" 2004
"3Mcompany"  "USA" 2005
"3Mcompany"  "USA" 2007
"3Mcompany"  "USA" 2008
"3Mcompany"  "USA" 2009
"3Mcompany"  "USA" 2010
"3Mcompany2" "DEU" 2003
"3Mcompany2" "DEU" 2003
"3Mcompany2" "DEU" 2004
"3Mcompany2" "DEU" 2005
"3Mcompany2" "DEU" 2007
"3Mcompany2" "DEU" 2009
"3Mcompany2" "FRA" 2003
"3Mcompany2" "FRA" 2004
"3Mcompany2" "FRA" 2005
end
The original data format. Array



And the finally data format like this pacture. Array



Explanation:
total_times:company A exist in country B of different year
period_times: If year in 2002 to 2005 without interruption is 1 period.
first_period_times:How many times in first period_times.
How to use stata code to achieve it.