Created
September 10, 2022 06:19
-
-
Save sachinsdate/e86ff6c8d68054bfda2fa31139c51e90 to your computer and use it in GitHub Desktop.
The code used in my article on proxy variables: https://towardsdatascience.com/how-to-use-proxy-variables-in-a-regression-model-539f723ab587
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import statsmodels.formula.api as smf | |
#Load the US Census Bureau data into a Dataframe | |
df = pd.read_csv('us_census_bureau_acs_2015_2019_subset.csv', header=0) | |
#Construct the model's equation in Patsy syntax. Statsmodels will automatically add the intercept and so we don't explicitly specify it in the model's equation | |
reg_expr = 'Percent_Households_Below_Poverty_Level ~ Median_Age + Homeowner_Vacancy_Rate + Percent_Pop_25_And_Over_With_College_Or_Higher_Educ' | |
#Build and train the model and print the training summary | |
olsr_model = smf.ols(formula=reg_expr, data=df) | |
olsr_model_results = olsr_model.fit() | |
print(olsr_model_results.summary()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment