I am using stata14. I have a panel database with the following structure: every group is a firm, SH_D are the shareholder stakes,
n Num_SH group SH_D Year
1 4 1 36.11 2011
2 4 1 26.93 2011
3 4 1 26.68 2011
4 4 1 10.26 2011
1 5 2 33.33 2011
2 5 2 33.33 2011
5 5 2 11.11 2011
4 5 2 11.11 2011
3 5 2 11.11 2011
For each group I need to get all the possible coalitions of shareholder with the corresponding coalition stake, and to get the coalition with the minimum stake >50. I use tuples to get all possible coalitions. Here is an example for the case of group 1
gen Coalition= ""
tuples 36.11 26.93 26.68 10.26, min(2)
set obs `ntuples'
forval i=1/`ntuples'{
replace Coalition = "`tuple`i''" in `i'
}
split Coalition
egen group=group(Coalition)
su group, meanonly
forvalues i = 1/`r(max)' {
destring Coalition`i' , generate(C_`i' )
}
ds C_*
egen CF_coalition = rowtotal(`r(varlist)')
ds C_*
egen N_coalition=rownonmiss(`r(varlist)')
gsort -CF_coalition
egen Min_CF_C=min(CF_coalition) if CF_coalition>=50
gen Min_N_C=N_coalition if CF_coalition==Min_CF_C
drop Coalition*
keep if Min_N_C!=. & Min_CF_C!=.
drop *coalition
missings dropvars,force
drop n group1 SH_D
I get one row for group one containing the informations I need : the total stake of the minimum stake coalition greater than 50, the stakes of the shareholders composing the coalition and the number of shareholder in the coalition.
Num_SH group Year C_1 C_2 Min_CF_C Min_N_C
4 1 2011 26.93 26.68 53.61 2
Problems:
1) I need to loop over all groups. Thus I need to read the list of shares from my database for each group. In the previous example the list was 36.11 26.93 26.68 10.26. Instead of providing by hand the required values, I need to retrieve the list of values. I tried the following:
levelsof SH_D
local list = r(levels)
tuples "`r(levels)'", min(2)
set obs `ntuples'
But it does not work!!
How can I make tuples to use a list a values created as a local list?
2) once I solve the previous problem I must cycle over all groups, get the previous final output for each group and append all those files to get the complete file. Any suggestion about the most efficient way to loop over groups?
Thanks
n Num_SH group SH_D Year
1 4 1 36.11 2011
2 4 1 26.93 2011
3 4 1 26.68 2011
4 4 1 10.26 2011
1 5 2 33.33 2011
2 5 2 33.33 2011
5 5 2 11.11 2011
4 5 2 11.11 2011
3 5 2 11.11 2011
For each group I need to get all the possible coalitions of shareholder with the corresponding coalition stake, and to get the coalition with the minimum stake >50. I use tuples to get all possible coalitions. Here is an example for the case of group 1
gen Coalition= ""
tuples 36.11 26.93 26.68 10.26, min(2)
set obs `ntuples'
forval i=1/`ntuples'{
replace Coalition = "`tuple`i''" in `i'
}
split Coalition
egen group=group(Coalition)
su group, meanonly
forvalues i = 1/`r(max)' {
destring Coalition`i' , generate(C_`i' )
}
ds C_*
egen CF_coalition = rowtotal(`r(varlist)')
ds C_*
egen N_coalition=rownonmiss(`r(varlist)')
gsort -CF_coalition
egen Min_CF_C=min(CF_coalition) if CF_coalition>=50
gen Min_N_C=N_coalition if CF_coalition==Min_CF_C
drop Coalition*
keep if Min_N_C!=. & Min_CF_C!=.
drop *coalition
missings dropvars,force
drop n group1 SH_D
I get one row for group one containing the informations I need : the total stake of the minimum stake coalition greater than 50, the stakes of the shareholders composing the coalition and the number of shareholder in the coalition.
Num_SH group Year C_1 C_2 Min_CF_C Min_N_C
4 1 2011 26.93 26.68 53.61 2
Problems:
1) I need to loop over all groups. Thus I need to read the list of shares from my database for each group. In the previous example the list was 36.11 26.93 26.68 10.26. Instead of providing by hand the required values, I need to retrieve the list of values. I tried the following:
levelsof SH_D
local list = r(levels)
tuples "`r(levels)'", min(2)
set obs `ntuples'
But it does not work!!
How can I make tuples to use a list a values created as a local list?
2) once I solve the previous problem I must cycle over all groups, get the previous final output for each group and append all those files to get the complete file. Any suggestion about the most efficient way to loop over groups?
Thanks
Comment