<jupyter_start><jupyter_text>Regressions behind Appendix A: Comparing Cityring-events  EVENT: CITYRING-PLANS ANNOUNCED (2005)<jupyter_code># Loading and creating base-data:
Apartments = pickle.load(open('/Users/holger/Documents/Python/Harmsen_Repo/Metro-Study/Pickles/Apartment Data API.pkl','rb'))
Apartments['Year Sold'] = [i.year for i in Apartments['Date_sold']]
Apartments['Closest Metro dist'] = [i['Distance'] for i in Apartments['Closest Metro']]
Apartments['Cityring'] = [i['Cityring'] for i in Apartments['Closest Metro']]
Apartments['log_price_sq_m_1000'] = np.log(Apartments['Price_sq_m_1000'])
# Generating Close-dummy:
Apartments['Close to Metro'] = 0
for i in range(0,len(Apartments)):
    if Apartments['Closest Metro dist'][i] < 0.5:
        Apartments['Close to Metro'][i] = 1

# Picking out those apartments having the cityring as the closest metro:
Cityring = Apartments[(Apartments['Cityring'] == 1)]
Cityring.reset_index(inplace=True)
# Creating Event-dataframe of the two tested years:
Cityring_04 = Cityring[(Cityring['Year Sold'] == 2004)]
Cityring_06 = Cityring[(Cityring['Year Sold'] == 2006)]

Event = pd.concat([Cityring_04,Cityring_06],ignore_index=True)
# Generating Announcement-Dummy:
Event['Announced'] = 0
for i in range(0,len(Event)):
    if Event['Year Sold'][i] == 2006:
        Event['Announced'][i] = 1
# Generating location dummies and deleting reference-area (those not being defined):
area_dummy = pd.get_dummies(Event['Area'])
del area_dummy['NaN']
# Generating dataframe to be regressed on:
X = pd.DataFrame()
X['Rooms'] = Event['Rooms']
X['Close to Metro'] = Event['Close to Metro']
X['Event'] = Event['Announced']
X['EventXClose'] = Event['Close to Metro'] * Event['Announced']
X = pd.merge(X,area_dummy,left_index=True,right_index=True)
X = sm.add_constant(X)
model = sm.OLS(Event['log_price_sq_m_1000'],X)
Results_Announced = model.fit(cov_type='HC1')
print(Results_Announced.summary())<jupyter_output>OLS Regression Results                            
===============================================================================
Dep. Variable:     log_price_sq_m_1000   R-squared:                       0.263
Model:                             OLS   Adj. R-squared:                  0.255
Method:                  Least Squares   F-statistic:                     43.48
Date:                 Wed, 05 Aug 2020   Prob (F-statistic):           2.52e-70
Time:                         09:52:15   Log-Likelihood:                -411.95
No. Observations:                  902   AIC:                             845.9
Df Residuals:                      891   BIC:                             898.7
Df Model:                           10                                         
Covariance Type:                   HC1                                         
==================================================================================
                     coef    std err          z      P>|z|      [0[...]<jupyter_text>EVENT: Cityring-Law passed in Parliament (2007)<jupyter_code>C2006 = Cityring[(Cityring['Year Sold'] == 2006)]
C2008 = Cityring[(Cityring['Year Sold'] == 2008)]

Event = pd.concat([C2006,C2008],ignore_index=True)
Event['Law Passed'] = 0
for i in range(0,len(Event)):
    if Event['Year Sold'][i] == 2008:
        Event['Law Passed'][i] = 1
# Generating location dummies:
Event['Metro_loc'] = [i['Metro'] for i in Event['Closest Metro']]
area_dummy = pd.get_dummies(Event['Area'])
del area_dummy['NaN']
X = pd.DataFrame()
X['Rooms'] = Event['Rooms']
X['Close to Metro'] = Event['Close to Metro']
X['Event'] = Event['Law Passed']
X['EventXClose'] = Event['Close to Metro'] * Event['Law Passed']
X = pd.merge(X,area_dummy,left_index=True,right_index=True)
X = sm.add_constant(X)
model = sm.OLS(Event['log_price_sq_m_1000'],X)
Results_Passed = model.fit(cov_type='HC1')
print(Results_Passed.summary())<jupyter_output>OLS Regression Results                            
===============================================================================
Dep. Variable:     log_price_sq_m_1000   R-squared:                       0.121
Model:                             OLS   Adj. R-squared:                  0.110
Method:                  Least Squares   F-statistic:                     15.68
Date:                 Wed, 05 Aug 2020   Prob (F-statistic):           1.37e-23
Time:                         09:52:15   Log-Likelihood:                -381.07
No. Observations:                  746   AIC:                             782.1
Df Residuals:                      736   BIC:                             828.3
Df Model:                            9                                         
Covariance Type:                   HC1                                         
==================================================================================
                     coef    std err          z      P>|z|      [0[...]<jupyter_text>EVENT: CONSTRUCTION BEGAN<jupyter_code>C2008 = Cityring[(Cityring['Year Sold'] == 2008)]
C2010 = Cityring[(Cityring['Year Sold'] == 2010)]

Event = pd.concat([C2008,C2010],ignore_index=True)
Event['Construction'] = 0
for i in range(0,len(Event)):
    if Event['Year Sold'][i] == 2010:
        Event['Construction'][i] = 1
# Generating location dummies:
area_dummy = pd.get_dummies(Event['Area'])
del area_dummy['NaN']
X = pd.DataFrame()
X['Rooms'] = Event['Rooms']
X['Close to Metro'] = Event['Close to Metro']
X['Event'] = Event['Construction']
X['EventXClose'] = Event['Close to Metro'] * Event['Construction']
X = pd.merge(X,area_dummy,left_index=True,right_index=True)
X = sm.add_constant(X)
model = sm.OLS(Event['log_price_sq_m_1000'],X)
Results_Construction = model.fit(cov_type='HC1')
print(Results_Construction.summary())<jupyter_output>OLS Regression Results                            
===============================================================================
Dep. Variable:     log_price_sq_m_1000   R-squared:                       0.090
Model:                             OLS   Adj. R-squared:                  0.079
Method:                  Least Squares   F-statistic:                     9.420
Date:                 Wed, 05 Aug 2020   Prob (F-statistic):           1.27e-13
Time:                         09:52:15   Log-Likelihood:                -478.95
No. Observations:                  727   AIC:                             977.9
Df Residuals:                      717   BIC:                             1024.
Df Model:                            9                                         
Covariance Type:                   HC1                                         
==================================================================================
                     coef    std err          z      P>|z|      [0[...]<jupyter_text>EVENT: BUILDING FINISHED (2019)<jupyter_code>C2018 = Cityring[(Cityring['Year Sold'] == 2018)]
C2020 = Cityring[(Cityring['Year Sold'] == 2020)]
Event = pd.concat([C2018,C2020],ignore_index=True)
Event['Opened'] = 0
for i in range(0,len(Event)):
    if Event['Year Sold'][i] == 2020:
        Event['Opened'][i] = 1
# Generating location dummies:
area_dummy = pd.get_dummies(Event['Area'])
del area_dummy['NaN']
X = pd.DataFrame()
X['Rooms'] = Event['Rooms']
X['Close to Metro'] = Event['Close to Metro']
X['Event'] = Event['Opened']
X['EventXClose'] = Event['Close to Metro'] * Event['Opened']
X = pd.merge(X,area_dummy,left_index=True,right_index=True)
X = sm.add_constant(X)
model = sm.OLS(Event['log_price_sq_m_1000'],X)
Results_Opening = model.fit(cov_type='HC1')
print(Results_Opening.summary())
pystout(models=[Results_Announced,Results_Passed,Results_Construction,Results_Opening],
        file='/Users/holger/Documents/Python/Harmsen_Repo/Metro-Study/Tex files/Metro Regressions 3.tex',
        digits=3,
        addnotes=['(*): ','(**)','(***)'],
        endog_names=['Announcement','Law passed','Construction Began','Opened'],
        varlabels={'const':'Constant','displacement':'Disp','mpg':'MPG'},
        mgroups={'y = log(Price per sq. m, DKK)':[1,3]},
        modstat={'nobs':'Obs','rsquared_adj':'Adj. R\sym{2}','fvalue':'F-stat'}
        )<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1897461057279529, 'fraction_numerical': 0.04084386115540292, 'mean_word_length': 2.532928942807626, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '442524', 'license': 'MIT', 'n_tokens_mistral': 2751, 'n_tokens_neox': 2411, 'n_words': 510, 'path': 'Metro-Study (SDS Exam)/Code/7) Event regressions (App. A).ipynb', 'repo_name': 'Holger-Harmsen/NumEcon', 'size': '8153'}