Dear Listers,

I have data regarding the anatomy of corporate control of different listed firms. The data is organized in pair of firms as it's shown below, and the variables are defined as:


rut: numeric id of each owner firm
rut_verif: the last digit of the "rut". It ranges from 0 to 9, and in exceptional cases it can take "k" or "e" values.
name: name of the owner firm
c_own_rut: numeric id of each subsidiary firm
c_own_rut_verif: the last digit of the "c_own_rut". It ranges from 0 to 9, and in exceptional cases it can take "k" or "e" values.
c_own_name_ name of the subsidiary firm
c_own_1: percentage of direct ownership that the owner firm has over the subsidiary
position: approximate position of the owner firm in the corporate anatomy of the holding
IDBG: id of the holding
fil_n: number of direct subsidiaries that the owner firm has.
firms_n: number of direct owners that the subsidiary has.


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
 rut rut_verif name c_own_rut c_own_rut_verif c_own_name c_own_1 position IDBG fil_n firms_n
91806000 "6" "Abastible S.A."                                        76565182 "4" "Abastible Internacional S.A."                              100 4 1 12 1
90690000 "9" "Empresas Copec S.A."                                   91806000 "6" "Abastible S.A."                                        99.1998 3 1 14 1
79874200 "0" "Via Limpia SpA"                                             999 ""   "Administradora Central de Estaciones de Servicio Ltda"      .1 5 1  5 2
79689550 "0" "Administradora de Estaciones de Servicios Serco Ltda."      999 ""  "Administradora Central de Estaciones de Servicio Ltda"    99.9 5 1  3 2
99520000 "7" "Compañía de Petroleos de Chile Copec S.A."           79689550 "0" "Administradora de Estaciones de Servicios Serco Ltda."    99.9 4 1 15 2
79874200 "0" "Via Limpia SpA"                                        79689550 "0" "Administradora de Estaciones de Servicios Serco Ltda."      .1 5 1  5 2
79874200 "0" "Via Limpia SpA"                                        79927140 "0" "Administradora de Servicios Generales Ltda"                 .1 5 1  5 2
79689550 "0" "Administradora de Estaciones de Servicios Serco Ltda." 79927140 "0" "Administradora de Servicios Generales Ltda"               99.9 5 1  3 2
77215640 "5" "Administradora de Ventas al Detalle Ltda."             77614700 "1" "Administradora de Servicios de Retail Ltda."              99.9 5 1  2 2
99520000 "7" "Compañía de Petroleos de Chile Copec S.A."           77215640 "5" "Administradora de Ventas al Detalle Ltda."              87.354 4 1 15 2
79689550 "0" "Administradora de Estaciones de Servicios Serco Ltda." 77215640 "5" "Administradora de Ventas al Detalle Ltda."              12.646 5 1  3 2
93458000 "1" "Celulosa Arauco y Constitución S.A."                         0 "E" "Agenciamiento y Servicios Profesionales S.A. de C.V."     .002 3 1 20 1
96563550 "5" "Inversiones Arauco Internacional Ltda."                       0 "E" "Agenciamiento y Servicios Profesionales S.A. de C.V."    99.99 4 1 20 2
94082000 "6" "Inversiones Siemel S.A."                               77072740 "5" "Agricola Siemel Ltda."                                 99.9858 2 1 10 1
99520000 "7" "Compañía de Petroleos de Chile Copec S.A."           96942120 "8" "Air BP Copec S.A."                                          50 4 1 15 2
99520000 "7" "Compañía de Petroleos de Chile Copec S.A."           76122974 "5" "Algae Fuels S.A."                                           44 4 1 15 2
76578731 "9" "Aprovisionadora Global de Energia S.A."                96761130 "1" "Andes Operaciones y Servicios S.A."                         50 4 1  5 1
93809000 "9" "Inversiones Angelini y Compañía Limitada"            96925430 "5" "AntarChile S.A."                                         74.01 1 1  3 .
90690000 "9" "Empresas Copec S.A."                                   76578731 "9" "Aprovisionadora Global de Energia S.A."                  39.83 3 1 14 1
96893820 "7" "Corpesca S.A."                                                0 "E" "Araguaia Nutrição Ltda."                               99.99 4 1 12 2
93458000 "1" "Celulosa Arauco y Constitución S.A."                         0 "E" "Arauco Argentina S.A."                                  9.9753 3 1 20 1
96563550 "5" "Inversiones Arauco Internacional Ltda."                       0 "E" "Arauco Argentina S.A."                                   90.01 4 1 20 2
96563550 "5" "Inversiones Arauco Internacional Ltda."                       0 "E" "Arauco Australia PTY Ltd."                                 100 4 1 20 2
93458000 "1" "Celulosa Arauco y Constitución S.A."                  96547510 "9" "Arauco Bioenergia S.A."                                     98 3 1 20 1
85805200 "9" "Forestal Arauco S.A."                                  96547510 "9" "Arauco Bioenergia S.A."                                      2 4 1 10 2
96510970 "6" "Maderas Arauco S.A."                                          0 "E" "Arauco Colombia S.A."                                     2.96 4 1  2 2
96637330 "K" "Servicios Logísticos Arauco S.A."                            0 "E" "Arauco Colombia S.A."                                     1.48 4 1  1 2
96563550 "5" "Inversiones Arauco Internacional Ltda."                       0 "E" "Arauco Colombia S.A."                                    92.61 4 1 20 2
93458000 "1" "Celulosa Arauco y Constitución S.A."                         0 "E" "Arauco Colombia S.A."                                   1.4778 3 1 20 1
85805200 "9" "Forestal Arauco S.A."                                         0 "E" "Arauco Colombia S.A."                                     1.48 4 1 10 2
96563550 "5" "Inversiones Arauco Internacional Ltda."                       0 "E" "Arauco Europe Cooperatief U.A."                          99.43 4 1 20 2
end
Now consider the case of the subsidiary "Administradora Central de Estaciones de Servicio Ltda." (from now on "firm B"). As you can see, firm B has 2 different owners: Via Limpia SpA (from now on firm A) and Administradora de Estaciones de Servicios Serco Ltda. (from now on firm C). To calculate the total ownership of firm B, i need to consider that firm A has direct ownership over firm B, but also indirect ownership through firm C (firm C owns 0.1% of firm B, and firm A owns 0.1% of firm C. Firm C owns 99.9% of firm B).
Hence, when we consider the relationship between the pair of firms, A owns 100% of the property of B (directly and through C). Then, when we consider cash flow rights of firm A over firm B, we have: 0.1+0.1*99.9=10.9%.

So the example above summarizes what i need to automatize. The thing is that i'm not sure how can i design a code that can identify the owners of a specific firm, and to do the operations needed to compute the total control and cash flow rights between a pair of firms.

Best regards,

Bastien Maire