standard-error

Error computing Robust Standard errors in Panel regression model (plm,R)

烂漫一生 提交于 2019-12-03 20:58:33
I am using the plm library to run fixed effect regressions and the sandwich,lmtest libraries to compute robust standard errors. I have no problem running the regressions, but in some instances when I go to compute the standard errors I get the following error: library(plm) library(sandwich) library(lmtest) fe_reg <- plm(y ~ x + I(x^2)+factor(date), data=reg_data, index=c("id","date"), model="within") coeftest(fe_reg, vcov.=vcovHC(fe_reg, type="HC1")) RRuntimeError: Error in solve.default(crossprod(demX)) system is computationally singular: reciprocal condition number = 1.84726e-25 I do not

Panel data regression: Robust standard errors

安稳与你 提交于 2019-12-03 13:27:45
问题 my problem is this: I get NA where I should get some values in the computation of robust standard errors. I am trying to do a fixed effect panel regression with cluster-robust standard errors. For this, I follow Arai (2011) who on p. 3 follows Stock/ Watson (2006) (later published in Econometrica, for those who have access). I would like to correct the degrees of freedom by (M/(M-1)*(N-1)/(N-K) against downward bias as my number of clusters is finite and I have unbalanced data. Similar

Clustered Standard Errors with data containing NAs

烂漫一生 提交于 2019-12-03 07:25:46
I'm unable to cluster standard errors using R and guidance based on this post . The cl function returns the error: Error in tapply(x, cluster1, sum) : arguments must have same length After reading up on tapply I'm still not sure why my cluster argument is the wrong length, and what is causing this error. Here is a link to the data set that I'm using. https://www.dropbox.com/s/y2od7um9pp4vn0s/Ec%201820%20-%20DD%20Data%20with%20Controls.csv Here is the R code: # read in data charter<-read.csv(file.choose()) View(charter) colnames(charter) # standardize NAEP scores charter$naep.standardized <-

robust standard errors in ggplot2

眉间皱痕 提交于 2019-11-30 23:18:56
I would like to plot a model with ggplot2. I have estimated a robust variance-covariance matrix which I would like to use when estimating the confidence interval. Can I tell ggplot2 to use my VCOV, or, alternatively, can I somehow force predict.lm to use my VCOV matrix? A dummy example: source("http://people.su.se/~ma/clmclx.R") df <- data.frame(x1 = rnorm(100), x2 = rnorm(100), y = rnorm(100), group = as.factor(sample(1:10, 100, replace=T))) lm1 <- lm(y ~ x1 + x2, data = df) coeftest(lm1) ## outputs coef.test, but can be modified to output VCOV clx(lm1, 1, df$group) It would be relatively

How to plot mean and standard error in Boxplot in R

喜夏-厌秋 提交于 2019-11-30 15:38:35
问题 I have two categorical factors ('Habitat' and 'Locality'), and one continuous variable (T). 'Habitat' has two level and 'Locality' has eight levels. I want to change the default whiskers to represent the SE, and the median into the mean for each boxplot. Is there a way to do this and taking both of the categorical factors into account when plotting? Many thanks in advance. This is what I have done with the default setting of boxplot ggplot, showing the first and third quartiles with median

How to plot mean and standard error in Boxplot in R

时间秒杀一切 提交于 2019-11-30 15:29:38
I have two categorical factors ('Habitat' and 'Locality'), and one continuous variable (T). 'Habitat' has two level and 'Locality' has eight levels. I want to change the default whiskers to represent the SE, and the median into the mean for each boxplot. Is there a way to do this and taking both of the categorical factors into account when plotting? Many thanks in advance. This is what I have done with the default setting of boxplot ggplot, showing the first and third quartiles with median intervals. ggplot(data,aes(x=Locality,y=T)) + geom_boxplot(aes(fill=interaction(Habitat,Locality), group

Fama MacBeth standard errors in R

一曲冷凌霜 提交于 2019-11-29 14:56:55
问题 Does anyone know if there is a package that would run Fama-MacBeth regressions in R and calculate the standard errors? I am aware of the sandwich package and its ability to estimate Newey-West standard errors, as well as providing functions for clustering. However, I have not seen anything with respect to Fama-MacBeth. 回答1: The plm package can estimate Fama-MacBeth regressions and SEs. require(foreign) require(plm) require(lmtest) test <- read.dta("http://www.kellogg.northwestern.edu/faculty

R - Lattice xyplot - How do you add error bars to groups and summary lines?

前提是你 提交于 2019-11-29 08:54:30
I'm posting this question because the very similar question here has not been answered until now. I have been asked to plot the mean +/- SEM of my whole cohort of patients over the xyplot() that depicts the values of all patients. The data used represents intraoperative cardiovascular findings from patients undergoing surgery. This is my data.frame called df dput(df) structure(list(Name = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("DE", "JS", "KG"

plotting barplots with standard errors using R

十年热恋 提交于 2019-11-28 14:30:13
I am trying to plot a simple barplot with standard errors and its driving me crazy. I did look up some examples and got as far as this: rt5 <- data.frame(rtgrp=c(37.2,38.0,38.3,38.5,38.9), mort=c(35,11,16,8,4), se=c(0.08,0.01,0.005,0.01,0.02)) rt5 xvals=with(rt5, barplot(mort,names.arg=rtgrp, xlab="PTEMP_R group mean",ylab="%",ylim=c(0,max(mort+10+se)))) I am trying to get through the last line of script but have been on it for quite a while: with(rt5, arrows(xvals,mort,xvals,mort+se,length=45,angle=90,code=3)) I would really love to get over this one! Thanks, Baz length is the size of the

Double clustered standard errors for panel data

帅比萌擦擦* 提交于 2019-11-28 07:48:34
I have a panel data set in R (time and cross section) and would like to compute standard errors that are clustered by two dimensions, because my residuals are correlated both ways. Googling around I found http://thetarzan.wordpress.com/2011/06/11/clustered-standard-errors-in-r/ which provides a function to do this. It seems a bit ad-hoc so I wanted to know if there is a package that has been tested and does this? I know sandwich does HAC standard errors, but it doesn't do double clustering (i.e. along two dimensions). Frank Harrell's package rms (which used to be named Design ) has a function