### Install mlsynth from GitHub Source: https://mlsynth.readthedocs.io Use pip to install the latest version of the library directly from the GitHub repository. ```bash pip install -U git+https://github.com/jgreathouse9/mlsynth.git ``` -------------------------------- ### Install mlsynth with optional extras Source: https://mlsynth.readthedocs.io Install specific optional backends using bracket syntax. Ensure the specifier is quoted to prevent shell globbing. ```bash # SCIP solver for SYNDES / MAREX pip install -U "mlsynth[design] @ git+https://github.com/jgreathouse9/mlsynth.git" # NumPyro for SPOTSYNTH's Bayesian mode pip install -U "mlsynth[bayes] @ git+https://github.com/jgreathouse9/mlsynth.git" # everything pip install -U "mlsynth[all] @ git+https://github.com/jgreathouse9/mlsynth.git" ``` -------------------------------- ### Reproduce ADH Proposition 99 with VanillaSC and CLUSTERSC Source: https://mlsynth.readthedocs.io Loads the California tobacco panel from the mlsynth repository, prepares the data with lagged-outcome predictors, and fits both a classical synthetic control (VanillaSC) and a robust OLS principal-component-regression control (CLUSTERSC). Prints the estimated average treatment effects for both methods. ```python import pandas as pd from mlsynth import VanillaSC, CLUSTERSC # California tobacco panel, 1970-2000: per-capita cigarette sales plus the # Abadie-Diamond-Hainmueller predictors. url = ("https://raw.githubusercontent.com/jgreathouse9/mlsynth/" "main/basedata/augmented_cali_long.csv") df = pd.read_csv(url) df = df[df["year"] <= 2000].copy() df["treated"] = ((df["state"] == "California") & (df["year"] >= 1989)).astype(int) # Three lagged-outcome predictors, as in ADH (2010), Table 2. for L in (1975, 1980, 1988): df[f"cig{L}"] = df["state"].map( df[df["year"] == L].set_index("state")["cigsale"]) covariates = ["loginc", "p_cig", "pct15-24", "pc_beer", "cig1975", "cig1980", "cig1988"] windows = {"loginc": (1980, 1988), "p_cig": (1980, 1988), "pct15-24": (1980, 1988), "pc_beer": (1984, 1988), "cig1975": (1975, 1975), "cig1980": (1980, 1980), "cig1988": (1988, 1988)} common = dict(df=df, outcome="cigsale", treat="treated", unitid="state", time="year", display_graphs=False) # Classical synthetic control on the canonical predictor set. sc = VanillaSC({**common, "covariates": covariates, "covariate_windows": windows, "backend": "mscmt", "canonical_v": "min.loss.w", "seed": 0}).fit() # Robust principal-component-regression control on the same outcomes. pcr = CLUSTERSC({**common, "method": "pcr", "pcr_objective": "OLS"}).fit() print(f"VanillaSC ATT = {sc.att:+.2f} packs/yr") print(f"OLS-PCR ATT = {pcr.att:+.2f} packs/yr") ``` ```text VanillaSC ATT = -18.98 packs/yr OLS-PCR ATT = -21.39 packs/yr ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.