Download the Jupyter Notebook for this section: formulation.ipynb

# Formulation Example¶

[1]:

import pyblp

pyblp.__version__

[1]:

'0.10.1'


In this example, we’ll design a matrix without an intercept, but with both prices and another numeric size variable.

[2]:

formulation = pyblp.Formulation('0 + prices + size')
formulation

[2]:

prices + size


Next, we’ll design a second matrix with an intercept, with first- and second-degree size terms, with categorical product IDs and years, and with the interaction of the last two. The first formulation will include include the fixed effects as indicator variables, and the second will absorb them.

[3]:

formulation1 = pyblp.Formulation('size + I(size ** 2) + C(product) * C(year)')
formulation1

[3]:

1 + size + I(size ** 2) + C(product) + C(year) + C(product):C(year)

[4]:

formulation2 = pyblp.Formulation('size + I(size ** 2)', absorb='C(product) * C(year)')
formulation2

[4]:

size + I(size ** 2) + Absorb[C(product)] + Absorb[C(year)] + Absorb[C(product):C(year)]


Finally, we’ll design a third matrix with an intercept and with a yearly trend interacted with the natural logarithm of income and categorical education. Absorption of continuous variables is not supported, so we need to use dummy variables.

[5]:

formulation = pyblp.Formulation('year:(log(income) + C(education))')
formulation

[5]:

1 + year:log(income) + year:C(education)