-2

I have to collapse some variable of my dataset but I’m getting issues.

Basically, there are 2 variables

  • valor_receita_propria (in English is own_revenue_value)
  • qt_tec_total (or total_tec_qt, the numberof technicians 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 equals 1, then the value of qt_tec_total of that plant actually refers to the whole enterprise. If in_refT equals 2, then the value of that plant refers to that singular plant.

What I need to do is aggregate 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)

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);

dan1st
  • 12,568
  • 8
  • 34
  • 67

1 Answers1

0

An if qualifier may be used at most once, as the syntax diagram for collapse makes clear. Your if statements are not even the same. Try

collapse (sum) receitasum=vl_receita_propria  (sum) tecsum=qt_tec_total (mean)  receitasum=vl_receita_propria (mean)  tecsum=qt_tec_total (sum) em_exerc (sum) doc_do (sum) qt_matricula_curso1, by (ano CO_MANT3 in_refC in_refT)

The syntax error is that once you have specified your first if qualifier, nothing else is legal except an in qualifier and/or options. Again, see the help for collapse.

Nick Cox
  • 35,529
  • 6
  • 31
  • 47