Download the Jupyter Notebook for this section: build_ownership.ipynb

Building Ownership Matrices Example

[1]:
import pyblp
import numpy as np

np.set_printoptions(threshold=100)
pyblp.__version__
[1]:
'0.10.1'

In this example, we’ll use the IDs created in the building ID data example to build a stack of standard ownership matrices. We’ll delete the first data row to demonstrate what ownership matrices should look like when markets have varying numbers of products.

[2]:
id_data = pyblp.build_id_data(T=2, J=5, F=4)
id_data = id_data[1:]
standard_ownership = pyblp.build_ownership(id_data)
standard_ownership
[2]:
array([[ 1.,  0.,  0.,  0., nan],
       [ 0.,  1.,  0.,  0., nan],
       [ 0.,  0.,  1.,  0., nan],
       [ 0.,  0.,  0.,  1., nan],
       [ 1.,  1.,  0.,  0.,  0.],
       [ 1.,  1.,  0.,  0.,  0.],
       [ 0.,  0.,  1.,  0.,  0.],
       [ 0.,  0.,  0.,  1.,  0.],
       [ 0.,  0.,  0.,  0.,  1.]])

We’ll now modify the default \(\kappa\) specification so that the elements associated with firm IDs 0 and 1 are equal to 0.5.

[3]:
def kappa_specification(f, g):
    if f == g:
       return 1
    return 0.5 if f < 2 and g < 2 else 0

We can use this specification to build a stack of alternative ownership matrices.

[4]:
alternative_ownership = pyblp.build_ownership(id_data, kappa_specification)
alternative_ownership
[4]:
array([[1. , 0.5, 0. , 0. , nan],
       [0.5, 1. , 0. , 0. , nan],
       [0. , 0. , 1. , 0. , nan],
       [0. , 0. , 0. , 1. , nan],
       [1. , 1. , 0.5, 0. , 0. ],
       [1. , 1. , 0.5, 0. , 0. ],
       [0.5, 0.5, 1. , 0. , 0. ],
       [0. , 0. , 0. , 1. , 0. ],
       [0. , 0. , 0. , 0. , 1. ]])

In addition to specifying a custom function, there are also a couple of special case strings that efficiently construct monopoly and single-product firm ownership matrices.

[5]:
monopoly_ownership = pyblp.build_ownership(id_data, 'monopoly')
monopoly_ownership
[5]:
array([[ 1.,  1.,  1.,  1., nan],
       [ 1.,  1.,  1.,  1., nan],
       [ 1.,  1.,  1.,  1., nan],
       [ 1.,  1.,  1.,  1., nan],
       [ 1.,  1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.,  1.]])
[6]:
single_ownership = pyblp.build_ownership(id_data, 'single')
single_ownership
[6]:
array([[ 1.,  0.,  0.,  0., nan],
       [ 0.,  1.,  0.,  0., nan],
       [ 0.,  0.,  1.,  0., nan],
       [ 0.,  0.,  0.,  1., nan],
       [ 1.,  0.,  0.,  0.,  0.],
       [ 0.,  1.,  0.,  0.,  0.],
       [ 0.,  0.,  1.,  0.,  0.],
       [ 0.,  0.,  0.,  1.,  0.],
       [ 0.,  0.,  0.,  0.,  1.]])