Skip to content

Commit

Permalink
update readme's (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
s3alfisc authored Jul 31, 2024
1 parent 5e1bd10 commit 5f120e8
Show file tree
Hide file tree
Showing 2 changed files with 588 additions and 81 deletions.
315 changes: 281 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ Nevertheless, for a quick introduction, you can take a look at the [documentatio

## Features

- **OLS**, **WLS** and **IV** Regression
- **OLS**, **WLS** and **IV** Regression (including IV diagnostics)
- **Poisson Regression** following the [pplmhdfe algorithm](https://journals.sagepub.com/doi/full/10.1177/1536867X20909691)
- Multiple Estimation Syntax
- Several **Robust** and **Cluster Robust Variance-Covariance** Estimators
- Wald Tests of Multiple Simultaneous Hypotheses
- **Wild Cluster Bootstrap** Inference (via
[wildboottest](https://github.com/py-econometrics/wildboottest))
- **Difference-in-Differences** Estimators:
Expand Down Expand Up @@ -71,6 +72,76 @@ data = pf.get_data()
pf.feols("Y ~ X1 | f1 + f2", data=data).summary()
```



<div id="W5xl50"></div>
<script type="text/javascript" data-lets-plot-script="library">
if(!window.letsPlotCallQueue) {
window.letsPlotCallQueue = [];
};
window.letsPlotCall = function(f) {
window.letsPlotCallQueue.push(f);
};
(function() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://cdn.jsdelivr.net/gh/JetBrains/[email protected]/js-package/distr/lets-plot.min.js";
script.onload = function() {
window.letsPlotCall = function(f) {f();};
window.letsPlotCallQueue.forEach(function(f) {f();});
window.letsPlotCallQueue = [];

};
script.onerror = function(event) {
window.letsPlotCall = function(f) {}; // noop
window.letsPlotCallQueue = [];
var div = document.createElement("div");
div.style.color = 'darkred';
div.textContent = 'Error loading Lets-Plot JS';
document.getElementById("W5xl50").appendChild(div);
};
var e = document.getElementById("W5xl50");
e.appendChild(script);
})()
</script>





<div id="9eFgOT"></div>
<script type="text/javascript" data-lets-plot-script="library">
if(!window.letsPlotCallQueue) {
window.letsPlotCallQueue = [];
};
window.letsPlotCall = function(f) {
window.letsPlotCallQueue.push(f);
};
(function() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://cdn.jsdelivr.net/gh/JetBrains/[email protected]/js-package/distr/lets-plot.min.js";
script.onload = function() {
window.letsPlotCall = function(f) {f();};
window.letsPlotCallQueue.forEach(function(f) {f();});
window.letsPlotCallQueue = [];

};
script.onerror = function(event) {
window.letsPlotCall = function(f) {}; // noop
window.letsPlotCallQueue = [];
var div = document.createElement("div");
div.style.color = 'darkred';
div.textContent = 'Error loading Lets-Plot JS';
document.getElementById("9eFgOT").appendChild(div);
};
var e = document.getElementById("9eFgOT");
e.appendChild(script);
})()
</script>



###

Estimation: OLS
Expand All @@ -82,7 +153,7 @@ pf.feols("Y ~ X1 | f1 + f2", data=data).summary()
|:--------------|-----------:|-------------:|----------:|-----------:|-------:|--------:|
| X1 | -0.919 | 0.065 | -14.057 | 0.000 | -1.053 | -0.786 |
---
RMSE: 1.441 R2: 0.609 R2 Within: 0.2
RMSE: 1.441 R2: 0.609 R2 Within: 0.2


### Multiple Estimation
Expand All @@ -96,26 +167,131 @@ syntax](https://aeturrell.github.io/coding-for-economists/econmt-regression.html
# OLS Estimation: estimate multiple models at once
fit = pf.feols("Y + Y2 ~X1 | csw0(f1, f2)", data = data, vcov = {'CRV1':'group_id'})
# Print the results
fit.etable()
pf.etable(fit.to_list())
```

est1 est2 est3 est4 est5 est6
------------ ----------------- ----------------- ----------------- ----------------- ----------------- -----------------
depvar Y Y2 Y Y2 Y Y2
------------------------------------------------------------------------------------------------------------------------------
Intercept 0.919*** (0.121) 1.064*** (0.232)
X1 -1.000*** (0.117) -1.322*** (0.211) -0.949*** (0.087) -1.266*** (0.212) -0.919*** (0.069) -1.228*** (0.194)
------------------------------------------------------------------------------------------------------------------------------
f2 - - - - x x
f1 - - x x x x
------------------------------------------------------------------------------------------------------------------------------
R2 0.123 0.037 0.437 0.115 0.609 0.168
S.E. type by: group_id by: group_id by: group_id by: group_id by: group_id by: group_id
Observations 998 999 997 998 997 998
------------------------------------------------------------------------------------------------------------------------------
Significance levels: * p < 0.05, ** p < 0.01, *** p < 0.001
Format of coefficient cell:
Coefficient (Std. Error)



<style type="text/css">
#T_6bd5a tbody tr:nth-child(0) td {
background-color: #f0f0f0;
}
#T_6bd5a tbody tr:nth-child(1) td {
border-bottom: 2px solid black;
}
#T_6bd5a tbody tr:nth-child(3) td {
border-bottom: 1px solid black;
}
#T_6bd5a tbody tr:nth-child(5) td {
border-bottom: 1px solid black;
}
#T_6bd5a tbody tr:nth-child(8) td {
border-bottom: 1px solid black;
}
#T_6bd5a tbody td {
background-color: #ffffff;
}
#T_6bd5a tbody tr td:first-child {
background-color: #f0f0f0;
font-weight: bold;
text-align: left;
}
#T_6bd5a_row0_col0, #T_6bd5a_row0_col1, #T_6bd5a_row0_col2, #T_6bd5a_row0_col3, #T_6bd5a_row0_col4, #T_6bd5a_row0_col5, #T_6bd5a_row0_col6, #T_6bd5a_row1_col0, #T_6bd5a_row1_col1, #T_6bd5a_row1_col2, #T_6bd5a_row1_col3, #T_6bd5a_row1_col4, #T_6bd5a_row1_col5, #T_6bd5a_row1_col6, #T_6bd5a_row2_col0, #T_6bd5a_row2_col1, #T_6bd5a_row2_col2, #T_6bd5a_row2_col3, #T_6bd5a_row2_col4, #T_6bd5a_row2_col5, #T_6bd5a_row2_col6, #T_6bd5a_row3_col0, #T_6bd5a_row3_col1, #T_6bd5a_row3_col2, #T_6bd5a_row3_col3, #T_6bd5a_row3_col4, #T_6bd5a_row3_col5, #T_6bd5a_row3_col6, #T_6bd5a_row4_col0, #T_6bd5a_row4_col1, #T_6bd5a_row4_col2, #T_6bd5a_row4_col3, #T_6bd5a_row4_col4, #T_6bd5a_row4_col5, #T_6bd5a_row4_col6, #T_6bd5a_row5_col0, #T_6bd5a_row5_col1, #T_6bd5a_row5_col2, #T_6bd5a_row5_col3, #T_6bd5a_row5_col4, #T_6bd5a_row5_col5, #T_6bd5a_row5_col6, #T_6bd5a_row6_col0, #T_6bd5a_row6_col1, #T_6bd5a_row6_col2, #T_6bd5a_row6_col3, #T_6bd5a_row6_col4, #T_6bd5a_row6_col5, #T_6bd5a_row6_col6, #T_6bd5a_row7_col0, #T_6bd5a_row7_col1, #T_6bd5a_row7_col2, #T_6bd5a_row7_col3, #T_6bd5a_row7_col4, #T_6bd5a_row7_col5, #T_6bd5a_row7_col6 {
text-align: right;
}
</style>
<table id="T_6bd5a">
<caption>Significance levels: * p < 0.05, ** p < 0.01, *** p < 0.001. Format of coefficient cell:
Coefficient (Std. Error)</caption>
<thead>
<tr>
<th id="T_6bd5a_level0_col0" class="col_heading level0 col0" ></th>
<th id="T_6bd5a_level0_col1" class="col_heading level0 col1" >est1</th>
<th id="T_6bd5a_level0_col2" class="col_heading level0 col2" >est2</th>
<th id="T_6bd5a_level0_col3" class="col_heading level0 col3" >est3</th>
<th id="T_6bd5a_level0_col4" class="col_heading level0 col4" >est4</th>
<th id="T_6bd5a_level0_col5" class="col_heading level0 col5" >est5</th>
<th id="T_6bd5a_level0_col6" class="col_heading level0 col6" >est6</th>
</tr>
</thead>
<tbody>
<tr>
<td id="T_6bd5a_row0_col0" class="data row0 col0" >depvar</td>
<td id="T_6bd5a_row0_col1" class="data row0 col1" >Y</td>
<td id="T_6bd5a_row0_col2" class="data row0 col2" >Y2</td>
<td id="T_6bd5a_row0_col3" class="data row0 col3" >Y</td>
<td id="T_6bd5a_row0_col4" class="data row0 col4" >Y2</td>
<td id="T_6bd5a_row0_col5" class="data row0 col5" >Y</td>
<td id="T_6bd5a_row0_col6" class="data row0 col6" >Y2</td>
</tr>
<tr>
<td id="T_6bd5a_row1_col0" class="data row1 col0" >Intercept</td>
<td id="T_6bd5a_row1_col1" class="data row1 col1" >0.919*** (0.121)</td>
<td id="T_6bd5a_row1_col2" class="data row1 col2" >1.064*** (0.232)</td>
<td id="T_6bd5a_row1_col3" class="data row1 col3" ></td>
<td id="T_6bd5a_row1_col4" class="data row1 col4" ></td>
<td id="T_6bd5a_row1_col5" class="data row1 col5" ></td>
<td id="T_6bd5a_row1_col6" class="data row1 col6" ></td>
</tr>
<tr>
<td id="T_6bd5a_row2_col0" class="data row2 col0" >X1</td>
<td id="T_6bd5a_row2_col1" class="data row2 col1" >-1.000*** (0.117)</td>
<td id="T_6bd5a_row2_col2" class="data row2 col2" >-1.322*** (0.211)</td>
<td id="T_6bd5a_row2_col3" class="data row2 col3" >-0.949*** (0.087)</td>
<td id="T_6bd5a_row2_col4" class="data row2 col4" >-1.266*** (0.212)</td>
<td id="T_6bd5a_row2_col5" class="data row2 col5" >-0.919*** (0.069)</td>
<td id="T_6bd5a_row2_col6" class="data row2 col6" >-1.228*** (0.194)</td>
</tr>
<tr>
<td id="T_6bd5a_row3_col0" class="data row3 col0" >f2</td>
<td id="T_6bd5a_row3_col1" class="data row3 col1" >-</td>
<td id="T_6bd5a_row3_col2" class="data row3 col2" >-</td>
<td id="T_6bd5a_row3_col3" class="data row3 col3" >-</td>
<td id="T_6bd5a_row3_col4" class="data row3 col4" >-</td>
<td id="T_6bd5a_row3_col5" class="data row3 col5" >x</td>
<td id="T_6bd5a_row3_col6" class="data row3 col6" >x</td>
</tr>
<tr>
<td id="T_6bd5a_row4_col0" class="data row4 col0" >f1</td>
<td id="T_6bd5a_row4_col1" class="data row4 col1" >-</td>
<td id="T_6bd5a_row4_col2" class="data row4 col2" >-</td>
<td id="T_6bd5a_row4_col3" class="data row4 col3" >x</td>
<td id="T_6bd5a_row4_col4" class="data row4 col4" >x</td>
<td id="T_6bd5a_row4_col5" class="data row4 col5" >x</td>
<td id="T_6bd5a_row4_col6" class="data row4 col6" >x</td>
</tr>
<tr>
<td id="T_6bd5a_row5_col0" class="data row5 col0" >R2</td>
<td id="T_6bd5a_row5_col1" class="data row5 col1" >0.123</td>
<td id="T_6bd5a_row5_col2" class="data row5 col2" >0.037</td>
<td id="T_6bd5a_row5_col3" class="data row5 col3" >0.437</td>
<td id="T_6bd5a_row5_col4" class="data row5 col4" >0.115</td>
<td id="T_6bd5a_row5_col5" class="data row5 col5" >0.609</td>
<td id="T_6bd5a_row5_col6" class="data row5 col6" >0.168</td>
</tr>
<tr>
<td id="T_6bd5a_row6_col0" class="data row6 col0" >S.E. type</td>
<td id="T_6bd5a_row6_col1" class="data row6 col1" >by: group_id</td>
<td id="T_6bd5a_row6_col2" class="data row6 col2" >by: group_id</td>
<td id="T_6bd5a_row6_col3" class="data row6 col3" >by: group_id</td>
<td id="T_6bd5a_row6_col4" class="data row6 col4" >by: group_id</td>
<td id="T_6bd5a_row6_col5" class="data row6 col5" >by: group_id</td>
<td id="T_6bd5a_row6_col6" class="data row6 col6" >by: group_id</td>
</tr>
<tr>
<td id="T_6bd5a_row7_col0" class="data row7 col0" >Observations</td>
<td id="T_6bd5a_row7_col1" class="data row7 col1" >998</td>
<td id="T_6bd5a_row7_col2" class="data row7 col2" >999</td>
<td id="T_6bd5a_row7_col3" class="data row7 col3" >997</td>
<td id="T_6bd5a_row7_col4" class="data row7 col4" >998</td>
<td id="T_6bd5a_row7_col5" class="data row7 col5" >997</td>
<td id="T_6bd5a_row7_col6" class="data row7 col6" >998</td>
</tr>
</tbody>
</table>





Expand All @@ -134,16 +310,16 @@ fit1.vcov("hetero").summary()
###

Estimation: OLS
Dep. var.: Y
Dep. var.: Y, Fixed effects:
Inference: hetero
Observations: 998

| Coefficient | Estimate | Std. Error | t value | Pr(>|t|) | 2.5% | 97.5% |
|:--------------|-----------:|-------------:|----------:|-----------:|-------:|--------:|
| Intercept | 0.919 | 0.112 | 8.223 | 0.000 | 0.699 | 1.138 |
| X1 | -1.000 | 0.082 | -12.134 | 0.000 | -1.162 | -0.838 |
| Intercept | 0.919 | 0.112 | 8.227 | 0.000 | 0.699 | 1.138 |
| X1 | -1.000 | 0.082 | -12.140 | 0.000 | -1.162 | -0.838 |
---
RMSE: 2.158 R2: 0.123
RMSE: 2.158 R2: 0.123


### Poisson Regression via `fepois()`
Expand Down Expand Up @@ -179,20 +355,91 @@ syntax:

```python
fit_iv = pf.feols("Y ~ 1 | f1 | X1 ~ Z1", data = data)
fit_iv.summary()
pf.etable([fit_iv._model_1st_stage, fit_iv])
```

###

Estimation: IV
Dep. var.: Y, Fixed effects: f1
Inference: CRV1
Observations: 997

| Coefficient | Estimate | Std. Error | t value | Pr(>|t|) | 2.5% | 97.5% |
|:--------------|-----------:|-------------:|----------:|-----------:|-------:|--------:|
| X1 | -1.025 | 0.115 | -8.930 | 0.000 | -1.259 | -0.790 |
---

<style type="text/css">
#T_52718 tbody tr:nth-child(0) td {
background-color: #f0f0f0;
}
#T_52718 tbody tr:nth-child(1) td {
border-bottom: 2px solid black;
}
#T_52718 tbody tr:nth-child(3) td {
border-bottom: 1px solid black;
}
#T_52718 tbody tr:nth-child(4) td {
border-bottom: 1px solid black;
}
#T_52718 tbody tr:nth-child(7) td {
border-bottom: 1px solid black;
}
#T_52718 tbody td {
background-color: #ffffff;
}
#T_52718 tbody tr td:first-child {
background-color: #f0f0f0;
font-weight: bold;
text-align: left;
}
#T_52718_row0_col0, #T_52718_row0_col1, #T_52718_row0_col2, #T_52718_row1_col0, #T_52718_row1_col1, #T_52718_row1_col2, #T_52718_row2_col0, #T_52718_row2_col1, #T_52718_row2_col2, #T_52718_row3_col0, #T_52718_row3_col1, #T_52718_row3_col2, #T_52718_row4_col0, #T_52718_row4_col1, #T_52718_row4_col2, #T_52718_row5_col0, #T_52718_row5_col1, #T_52718_row5_col2, #T_52718_row6_col0, #T_52718_row6_col1, #T_52718_row6_col2 {
text-align: right;
}
</style>
<table id="T_52718">
<caption>Significance levels: * p < 0.05, ** p < 0.01, *** p < 0.001. Format of coefficient cell:
Coefficient (Std. Error)</caption>
<thead>
<tr>
<th id="T_52718_level0_col0" class="col_heading level0 col0" ></th>
<th id="T_52718_level0_col1" class="col_heading level0 col1" >est1</th>
<th id="T_52718_level0_col2" class="col_heading level0 col2" >est2</th>
</tr>
</thead>
<tbody>
<tr>
<td id="T_52718_row0_col0" class="data row0 col0" >depvar</td>
<td id="T_52718_row0_col1" class="data row0 col1" >Y</td>
<td id="T_52718_row0_col2" class="data row0 col2" >Y</td>
</tr>
<tr>
<td id="T_52718_row1_col0" class="data row1 col0" >Z1</td>
<td id="T_52718_row1_col1" class="data row1 col1" >0.396*** (0.014)</td>
<td id="T_52718_row1_col2" class="data row1 col2" ></td>
</tr>
<tr>
<td id="T_52718_row2_col0" class="data row2 col0" >X1</td>
<td id="T_52718_row2_col1" class="data row2 col1" ></td>
<td id="T_52718_row2_col2" class="data row2 col2" >-1.025*** (0.115)</td>
</tr>
<tr>
<td id="T_52718_row3_col0" class="data row3 col0" >f1</td>
<td id="T_52718_row3_col1" class="data row3 col1" >x</td>
<td id="T_52718_row3_col2" class="data row3 col2" >x</td>
</tr>
<tr>
<td id="T_52718_row4_col0" class="data row4 col0" >R2</td>
<td id="T_52718_row4_col1" class="data row4 col1" >0.419</td>
<td id="T_52718_row4_col2" class="data row4 col2" >-</td>
</tr>
<tr>
<td id="T_52718_row5_col0" class="data row5 col0" >S.E. type</td>
<td id="T_52718_row5_col1" class="data row5 col1" >by: f1</td>
<td id="T_52718_row5_col2" class="data row5 col2" >by: f1</td>
</tr>
<tr>
<td id="T_52718_row6_col0" class="data row6 col0" >Observations</td>
<td id="T_52718_row6_col1" class="data row6 col1" >994</td>
<td id="T_52718_row6_col2" class="data row6 col2" >997</td>
</tr>
</tbody>
</table>




## Call for Contributions

Expand Down
Loading

0 comments on commit 5f120e8

Please sign in to comment.