hot to collapse 2 variables by dummies in panel data [stata] : I have to collapse a some variable of my dataset but I’m getting issues.

Basicaly, there are 2 variables valor_receita_propria (in english is own_revenue_value) and qt_tec_total (or total_tec_qt, the quantity of technician in a institution). There are 2 dummy variables which specify if the value of the above mentioned variables refer to each individual plant or to his enterprise.

For example, if in_refT is equal 1, then the value of qt_tec_total of that plant actually refers to the whole enterprise. If the inrefT is equal 2, then the value of that plant refers to that singular plnat. 
What I need to do is agregate all the values for enterprise. My plan was take the mean of all values referring to the enterprise and take the sum of all values referring to each plant, so I wrote:
“
. collapse (sum) receitasum=vl_receita_propria  if  in_refC==2 (sum) tecsum=qt_tec_total if  in_refT==2 (mean)  receitasum=vl_receita_propria if in_refC==1 (mean)  tecsum=qt_tec_total if  in_refT==1 (sum) em_exerc (sum) doc_do (sum) qt_matricula_curso1, by (ano CO_MANT3)
“
Of course, I need that it results only one variable of each kind referring only and exclusively to each whole enterprise.
However, it shows this error:
“
invalid '('
r(198);
 “