Skip to content

simulate_frac_nodemog_data module

Helper script to simulate FRAC datasets used in tutorials.

simulate_frac_nodemog_data(T=50, J=20, n_X1_exo=1, n_X1_endo=1, n_X2_exo=0, n_X2_endo=1, n_Z=1, sigma_x=1.0, sigma_xi=1.0, rho_x_xi=np.sqrt(0.5), rho_x_z=np.sqrt(0.5), betas=np.array([-4.3, 1.0]), sigmas=np.array([1.0]))

Simulate FRAC data with endogenous random-coefficient regressors.

Returns:

Name Type Description
FracNoDemogSimulatedData FracNoDemogSimulatedData

Simulated dataset ready for FRAC estimation.

Source code in frac_blp/simulate_frac_nodemog_data.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def simulate_frac_nodemog_data(
    T: int = 50,
    J: int = 20,
    n_X1_exo: int = 1,
    n_X1_endo: int = 1,
    n_X2_exo: int = 0,
    n_X2_endo: int = 1,
    n_Z: int = 1,
    sigma_x: float = 1.0,
    sigma_xi: float = 1.0,
    rho_x_xi: float = np.sqrt(0.5),
    rho_x_z: float = np.sqrt(0.5),
    betas: np.ndarray = np.array([-4.3, 1.0]),
    sigmas: np.ndarray = np.array([1.0]),
) -> FracNoDemogSimulatedData:
    """
    Simulate FRAC data with endogenous random-coefficient regressors.

    Returns:
        FracNoDemogSimulatedData: Simulated dataset ready for FRAC estimation.
    """
    n_X1 = n_X1_exo + n_X1_endo
    n_X2 = n_X2_exo + n_X2_endo
    names_X1_exo = ["constant"]
    if n_X1_exo > 1:
        names_X1_exo += [f"x_{i + 1}" for i in range(n_X1_exo - 1)]
    names_X1_endo = []
    names_X1_endo = [f"x_{i}" for i in range(n_X1_exo, n_X1)]
    names_X2_exo = [f"x_{i + 1}" for i in range(n_X2_exo)]
    names_X2_endo = [f"x_{i + 1}" for i in range(n_X2_exo, n_X2)]

    return FracNoDemogSimulatedData(
        T=T,
        J=J,
        names_X1_exo=names_X1_exo,
        names_X1_endo=names_X1_endo,
        names_X2_exo=names_X2_exo,
        names_X2_endo=names_X2_endo,
        n_Z=n_Z,
        sigma_x=sigma_x,
        sigma_xi=sigma_xi,
        rho_x_z=rho_x_z,
        rho_x_xi=rho_x_xi,
        betas=betas,
        sigmas=sigmas,
    )