Skip to main content
33 votes

Replicating Stata's "robust" option in R

I found a description on the following website that replicates Stata's ''robust'' option in R. https://economictheoryblog.com/2016/08/08/robust-standard-errors-in-r Following the instructions, all ...
Alex Rato's user avatar
  • 363
21 votes

Average Marginal Effects interpretation

The average marginal effect gives you an effect on the probability, i.e. a number between 0 and 1. It is the average change in probability when x increases by one unit. Since a probit is a non-linear ...
Maarten Buis's user avatar
  • 21.2k
15 votes

Replicating Stata's "robust" option in R

As of April 2018 I believe you want the estimatr package, which provides a near drop in replacement for lm. Several examples ...
alexpghayes's user avatar
11 votes
Accepted

What are the differences between tests for overidentification in 2SLS

There are a lot of questions here, so I'll first give an overview, and then explain a bit more. You have 4 tests you're asking about: Hausman test, Sargan test, a Wald test of exogeneity, and a Hansen ...
doubled's user avatar
  • 4,957
10 votes

Time varying covariates in longitudinal mixed effect models

Dealing with time-varying covariates in mixed models but also in general is a challenging task. A few points to consider: I would differentiate between time-varying covariates, such as smoking, and ...
Dimitris Rizopoulos's user avatar
10 votes

Regressors Became Statistically Insignificant Upon Correcting for Autocorrelation

One possibility is that both your dependent and independent variables are related to time. This is the source of many humorous correlations such as: Ice cream sales go up when sharks attack or ...
Peter Flom's user avatar
  • 124k
9 votes
Accepted

Different P value of Mann-Whitney-Wilcoxon between R and Stata

The reason for the dramatic difference is that you have run the Wilcoxon test incorrectly in R. You probably intended: > wilcox.test(passem$temp ~ died30in)
Gordon Smyth's user avatar
  • 13.1k
9 votes
Accepted

How to do maximum likelihood estimation when numerical derivatives cannot be calculated

There are optimisation algorithms that don't require derivatives. You can divide them into algorithms that assume derivatives exist but don't require them algorithms that don't assume smoothness A ...
Thomas Lumley's user avatar
9 votes

Cannot seem to find a statistical difference despite a clear difference in the dataset

I tried to replicate @dimitriy's results in Python and got slightly different results: ...
Igor F.'s user avatar
  • 9,353
8 votes

Predicted Probabilities vs. Marginal Effects using at means or asObserved in Stata 14 Margins

In a logit model, $$Pr[y = 1 \vert x, d] = p = \frac{\exp (\alpha + \beta \cdot x + \gamma \cdot d)}{1+\exp (\alpha + \beta \cdot x + \gamma \cdot d)}. $$ After some tedious calculus and ...
dimitriy's user avatar
  • 36.4k
8 votes
Accepted

Which R-squared value to report while using a fixed effects model - within, between or overall?

All three of these values provide some insight into your model, so you may need to report all three, but the within value is typically of main interest, as fixed-effects is known as the within ...
AlexK's user avatar
  • 1,127
8 votes
Accepted

Residuals dont sum to zero: Stata bug? Or User error?

The residuals should not typically sum to zero in weighted least squares, generalised least squares, or mixed models for unbalanced panel data. The regression coefficients are solving some equation ...
Thomas Lumley's user avatar
7 votes

Python as a statistics workbench

I believe Python is a superior workbench in my field. I do a lot of scraping, data wrangling, large data work, network analysis, Bayesian modeling, and simulations. All of these things typically need ...
7 votes

How to determine the appropriate number of lags when using Newey-West (or HAC) standard errors

My answer is going to expand on what @Achim mentioned as "the growth rate of this lag length parameter". Newey & West (1987, Econometrica, p. 705) show that their estimator for the ...
Candamir's user avatar
  • 1,030
7 votes
Accepted

Alternatives to multilevel model with log transformed outcome

This is a great use case for the inverse hyperbolic sine transformation [1], [2]: $$ \log\left( y + \sqrt{y^2 + 1} \right) $$ Except for very small values of y, the inverse sine is approximately ...
shadowtalker's user avatar
  • 12.7k
7 votes

Fitting a smoothed curve to a noisy data

Sounds like you just need to adjust the smoothing parameters (sometimes called bandwidth) to your liking. Either of these methods should be able to be tuned appropriately. Moving average can be ...
Underminer's user avatar
  • 4,139
7 votes

Calculating weights for inverse probability weighting for the treatment effect on the untreated/non-treated

For ATU, the weights on $y_i$ would be $$ w_i = \begin{cases} \frac{1 - \hat p(x_i)}{\hat p(x_i)} & \text{if}\ d_i=1 \\ 1 & \text{if}\ d_i=0, \end{cases} $$ where $d_i$ is the ...
dimitriy's user avatar
  • 36.4k
7 votes
Accepted

Predicting probabilities after log-linear regression

You have a problem that your predicted prices will be too small since $$E[y \vert x]=\exp(x'\beta) \cdot E[\exp(u)],$$ and you are leaving off the last factor. This is a consequence of Jensen's ...
dimitriy's user avatar
  • 36.4k
7 votes
Accepted

How to add error bar plots into a parameter table?

It's called a forest plot, you can download the r package. It's about getting the data into the right format required by the plot. We can use a dataset from metafor,...
StupidWolf's user avatar
  • 5,137
7 votes
Accepted

Under what circumstances should the degrees of freedom for a Welch's t-test be N-1?

It is possible, but unlikely. If both sample sizes are $n$ then the effective number of degrees of freedom is bounded between between $n-1$ and $2n-2$, and near to the top end either if the variances ...
Henry's user avatar
  • 40.2k
6 votes

Why does a confidence interval including 0 mean the difference is not significant?

"Having zero in one's confidence interval implies that a treatment effect has no effect." : This is often how such confidence intervals are interpreted, but this is a mistake. A confidence ...
Xisco Bernal Tortosa's user avatar
6 votes

Including several endogenous interaction terms

There could all sorts of things going on, but without knowing more about the details of your model and actual commands and results, it will be hard to say more. Don't show us pseudo-code with generic ...
dimitriy's user avatar
  • 36.4k
6 votes
Accepted

different results grouped survey standard deviation in Stata and R

What's happening is that R and Stata use quite different approaches to estimating the population standard deviation. R goes directly via the mean of $(X-\bar X)^2$ and Stata goes via an estimated ...
Thomas Lumley's user avatar
6 votes
Accepted

How to run svy: regress in R or get R-squared in R for complex survey data

For a Gaussian glm (where the population parameter is the OLS parameter) you can just divide the dispersion parameter by the population variance and subtract from 1 Using one of the examples from the ...
Thomas Lumley's user avatar
6 votes

Discrepancy in Cholesky decomposition matrix from variance covariance matrix obtained in Stata and R using regression

From the Stata documentation, the cholesky function returns a lower triangular matrix $G$ such that $A = GG'$ given input matrix $A$. Meanwhile, from the R ...
josliber's user avatar
  • 4,377
6 votes

Survey design for multilevel models

Executive summary: this is much harder than you would expect, and there is neither a standard implementation, nor even an accepted estimator. Let's fix some terminology. In a survey, you have ...
Thomas Lumley's user avatar
6 votes

Cannot seem to find a statistical difference despite a clear difference in the dataset

You can detect a positive additive effect of both surgical and endovascular, though not surgical on its own. Jointly, both effects are marginally significant. These effects are relative to just ...
dimitriy's user avatar
  • 36.4k
6 votes

Regressors Became Statistically Insignificant Upon Correcting for Autocorrelation

Autocorrelation Influences My answer is a bit of a two-parter, the second part largely being more important than the first. First, a bit about autocorrelation... Consider the following data that I ...
Shawn Hemelstrand's user avatar
5 votes

How to replicate Stata's robust binomial GLM for proportion data in R?

You can replicate the UCLA FAQ on proportions (with a percentage as a dependent variable) as follows: ...
landroni's user avatar
  • 1,133
5 votes

F-test differences Stata and R

update: I´ve crossposted the question at statalist.org and got an answer there: http://www.statalist.org/forums/forum/general-stata-discussion/general/1348073-f-test-differences-stata-and-r basically ...
user115328's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible