Hi all,

I am a master student and I am trying to estimate effect of sanctions on import. Database consists of import flows into the country: firm id, date, origin, product (hs code) and value of trade flow.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str148 id str10 date str3 destination int hs float tradeflow
"1"   "2012-01-26" "IL"  709   22994.4
"2"   "2014-02-24" "AR"  207     32250
"3"   "2015-07-07" "BR"  206     24700
"4" "2014-01-02" "IL"  709  14424.11
"5"  "2013-10-07" "BE"  404  46373.64
"6"  "2012-09-18" "UA" 2103   2548.02
"7"    "2016-02-25" "SY"  805   6728.42
"7"    "2016-02-25" "SY"  706   6237.09
"7"    "2016-02-25" "SY"  704   16773.8
"7"    "2016-02-27" "SY"  805  34031.54
"7"    "2016-02-27" "SY"  805  14945.36
"7"    "2016-02-28" "SY"  706  13029.18
"7"    "2016-03-01" "SY"  805 160932.55
"8"  "2012-01-25" "TR" 2106   5557.58
"8"  "2012-01-25" "TR" 2102      2500
"8"  "2013-12-07" "TR" 1901    532.76
"8"  "2013-12-07" "TR" 2106   3092.71
"8"  "2015-07-24" "TR" 2106   2009.82
"9"    "2012-01-11" "TR"  804     50000
"9"    "2012-04-12" "CL"  806     86100
end
I have 2 problems:

1. I would like to include firm x destination x product, firm x date x product, destination x product x time fixed effects. How can i do that?

basically i run the following regression: reghdfe import sanctionregressors, absorb(firmID origin product). However, it takes into account only 1-dimensional fixed effects and i need 3-dimensional.

2. I would like to sum trade flows by id, destination, hs codes with condition some dummy variable equals 1. How can i do that?

For example, i want to get this dataset:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str148 id str10 date str3 destination int hs float tradeflow
"1"   "2012-01-26" "IL"  709   22994.4
"2"   "2014-02-24" "AR"  207     32250
"3"   "2015-07-07" "BR"  206     24700
"4" "2014-01-02" "IL"  709  14424.11
"5"  "2013-10-07" "BE"  404  46373.64
"6"  "2012-09-18" "UA" 2103   2548.02
"7"    "2016-02-25" "SY"  805   6728.42 + 34031.54 + 14945.36 + 160932.55
"7"    "2016-02-25" "SY"  706   6237.09 + 13029.18
"7"    "2016-02-25" "SY"  704   16773.8 
"8"  "2012-01-25" "TR" 2106   5557.58 + 3092.71 
"8"  "2012-01-25" "TR" 2102      2500
"8"  "2013-12-07" "TR" 1901    532.76
"8"  "2015-07-24" "TR" 2106   2009.82
"9"    "2012-01-11" "TR"  804     50000
"9"    "2012-04-12" "CL"  806     86100
end