Giter Site home page Giter Site logo

gsynth's Introduction

gsynth

Lifecycle: stable License: MIT

gsynth implements the generalized synthetic control method, which imputes counterfactuals for each treated unit using control group information based on a linear interactive fixed effects model. This version supports unbalanced panels and implements the matrix completion method.

Authors: Yiqing Xu (Stanford), Licheng Liu (MIT)

Date: Feb 22, 2022

Repos: Github (1.2.1) CRAN (1.2.1)

Example: R code used in the tutorial can be downloaded from here.


Installation

You can install gsynth directly from CRAN by typing the following command in the R console:

install.packages('gsynth', type = 'source')

You can also install the development version of the package from Github by typing:

install.packages('devtools', repos = 'http://cran.us.r-project.org') # if not already installed
devtools::install_github('xuyiqing/gsynth')

gsynth depends on the following packages, which will be installed automatically when gsynth is being installed; you can also install them manually:

## for processing C++ code
require(Rcpp) 
## for plotting
require(ggplot2)  
require(GGally) 
## for parallel computing 
require(foreach)  
require(future)
require(doParallel) 
require(abind) 
require(lfe)

Notes on installation failures

  1. Quick solution: download a binary build (v.1.2.1), which does not require compilation, and install it from file in RStudio.
  2. Windows users please consider upgrading R to 4.0.0 or higher and installing the latest Rtools to avoid C++17 complier errors when installing fastplm.
  3. For Rcpp, RcppArmadillo and MacOS “-lgfortran” and “-lquadmath” error, click here for details.
  4. Installation failure related to OpenMP on MacOS, click here for a solution.
  5. To fix these issues, try installing gfortran 6.1 from here.
  6. Mac users who have updated to MacOS Big Sur will likely encounter compilation problems. See here for a potential solution.

Report bugs

Please report bugs to yiqingxu [at] stanford.edu with your sample code, data file, and a treatment status plot generated by panelview. Much appreciated!

gsynth's People

Contributors

beniaminogreen avatar liulch avatar xuyiqing avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gsynth's Issues

plot factor loadings with only 1 treated

There appears to be a problem with plotting the factor loadings for a model with only 1 (<3?) treated unit.

Some function makes calls to cor.test passing the factor loadings as data. First using the control units, which works fine. But then a call is made with just the treated observations, and since there's only one observation, cor.test fails as it requires a minimum of 3 observations.

The debug is confusing me a bit, but the call to cor.test seems to be made from somewhere in the proximity of GGally::ggmatrix

Second time fails:

  plotMatrix <- list(data = data, plots = plots, title = title, 
    xlab = xlab, ylab = ylab, showStrips = showStrips, xAxisLabels = xAxisLabels, 
    yAxisLabels = yAxisLabels, showXAxisPlotLabels = showXAxisPlotLabels, 
    showYAxisPlotLabels = showYAxisPlotLabels, labeller = labeller, 
    switch = switch, xProportions = xProportions, yProportions = yProportions, 
    progress = progress, legend = legend, gg = gg, nrow = nrow, 
    ncol = ncol, byrow = byrow)
  attributes(plotMatrix)$class <- c("gg", "ggmatrix")
  plotMatrix

Example (using data from package augsynth:

df <- as.data.frame(augsynth::kansas)
library(gsynth)

gsynth_mod <- gsynth(lngdpcapita ~ treated, data = df, index = c("fips", "year_qtr"), force = "unit", 
                     se = TRUE, CV = TRUE)

plot(gsynth_mod, type = "factors")
plot(gsynth_mod, type = "loadings")

Latex and gsynth output

Greetings:
This question is nominally about gsynth so I can delete it if this forum is not the right place. OTOH, I thought that users (other than me) could benefit from a response.

What is an easy way to generate Latex table from gsynth output (short of hand generating a Latex table from the returned output object)? I tried "stargazer" but that did not work.

Zia

return synthetic control group weights from gsynth function

Hi, just wondering if it's already returned in the object from gsynth(), if yes, could you please point the list element name? and if no, would you like to add it as a new feature in this function?
Because understanding how the algorithm assign weights to each unit in the control group will be quite interesting. Thanks!

related stackoverflow question here

Are all treatment times shifted towards {T_0} when doing Matrix Completion?

Hi, I was wondering whether all observations are shifted such that $T_0$ (or the first time period with treatment) are the same before computing the Matrix Completion? Or this shift is only done when computing ATTs?

After having read the paper a few times, I assume that that is the case for computing the interactive fixed effects with factor loadings, but I am not sure about the Matrix Completion. Could you please help clarify this? Thank you very much in advance!

PC criterion of factor selection

Hi, is the PC criterion in the cross validation, Principal Component criterion of factor selection? Is there an order in which the factor number is selected? That is, min MSPE> min PC> min IC? The vignette is not very specific on this. Thank you very much.

"Error: could not find function 'panelView'"

Here is my session info:

R version 3.4.3 (2017-11-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.1

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] parallel stats graphics grDevices utils datasets methods base

other attached packages:
[1] abind_1.4-5 doParallel_1.0.11 iterators_1.0.9 foreach_1.4.4 GGally_1.3.2
[6] ggplot2_2.2.1 Rcpp_0.12.15 gsynth_1.0.6

loaded via a namespace (and not attached):
[1] mvtnorm_1.0-7 codetools_0.2-15 reshape_0.8.7 grid_3.4.3 plyr_1.8.4
[6] gtable_0.2.0 scales_0.5.0 pillar_1.2.1 rlang_0.2.0 lazyeval_0.2.1
[11] RColorBrewer_1.1-2 tools_3.4.3 munsell_0.4.3 compiler_3.4.3 colorspace_1.3-2
[16] tibble_1.4.2

Thank you in advance for assistance.

Typo in ATE Plot

In the plot from the users guide:
plot(out, type = "counterfactual", raw = "all")
grafik
it says treated Avearge instead of treated Average. I noticed this also in my own plots. Therefore its propably a typo in the plot method.

Is there a way to obtain the ggplot object used for the plot directly?

Error occurred when stalling gsynth 1.1.6 from GitHub

Has anyone ever come across the following problem when installing gsynth 1.1.6 from GitHub?
The code and the error message are as follows:

devtools::install_github('xuyiqing/gsynth')
Error in normalizePath(key$InstallPath, mustWork = FALSE, winslash = "/")

Do you have any idea about how to solve this?

Understanding EM algorithm in gsynth

Hi Yiqing,

Thanks for making such a fantastic package.

I am running an experiment with only 1 treated unit (N_tr = 1) and 38 units in the control group (N_co = 38). The dataset is unbalanced. I have completed the tutorial you have uploaded on your website. (http://yiqingxu.org/software/gsynth/gsynth_examples.html). It seems like "gsynth" can handle unbalanced panel dataset by using the EM algorithm. My question is related to the output of "gsynth". The output only shows NA values in the missing rows. To be precise, the algorithm did not estimate ATT where missing values exists. I thought that the EM algorithm would fill in missing values. You can find the example code below.

Best regards,
Yafee

#####################

Code

#####################

library(gsynth)
library(data.table)

Datasets

data(gsynth)
names(turnout)

Set seed

set.seed(123456)

Remove rows

turnout.ub <- turnout[-c(which(turnout$abb=="WY")[1:15], sample(1:nrow(turnout),50,replace=FALSE)),]

Overview of missing values

panelView(turnout ~ policy_edr + policy_mail_in + policy_motor, data = turnout.ub, index = c("abb","year"), pre.post = TRUE)

Transform to data.table object

setDT(turnout.ub)

Remove all treated units without ID

turnout.ub <- turnout.ub[!(abb %in% c("CT","IA","ME","MN","MT","NH","WI","WY"))]

Run gsynth

out <- gsynth(turnout ~ policy_edr + policy_mail_in + policy_motor,
data = turnout.ub,
index = c("abb","year"),
se = TRUE,
inference = "parametric",
r = c(0, 5),
CV = TRUE,
force = "two-way",
EM = TRUE,
parallel = TRUE,
min.T0 = 8,
nboots = 1000,
seed = 02139)

print results

out

Issue with control varaibles

Hi, I'm having issues with including control variables in gsynth. These controls are industry fixed effects. I am receiving the following error message:

Error in gsynth.default(formula = NULL, data = data, Y = Yname, D = Dname, :
Variable "total.SICCD.f1381" is unit-invariant. Try to remove it.

Does this error imply that this method can not include fixed effects beyond unit and time specifications?
The variable it is flagging is a dummy variable reading 1 for firms in a certain industry and 0 otherwise. There are around 40 of these dummies. If I remove this variable it sends the same message for the next variable of this kind.

Thanks,
WC

Error when using clustered bootstrap.

I am using version 1.16 of gsynth.

I have run into errors trying to use the cluster option when bootstrapping standard errors.

out0 <- gsynth(turnout ~ policy_edr + policy_mail_in + policy_motor, data = turnout, index = c("abb","year"), se = TRUE, inference = "parametric", r = 0, CV = FALSE, force = "two-way", nboots = 1000, seed = 02139, cl = "abb" )

I get the following error:

Parallel computing ...
Bootstrapping ... ...
Error in eff.boot[, , j] <- boot.out[[j]]$eff : 
  incorrect number of subscripts

The same code runs fine if I drop the cluster option.

It looks like the error comes from here.

I get the same error if I set force = "none" as an option as well.

Does the error happen because the cluster level is the same level as the fixed effects?

problem with single case treatment in gsynth - get Error in rowSums(Y.ct) : 'x' must be an array of at least two dimensions

hello

I have some trouble with the gsynth function using r on OS

I want to analyse the economic growth effects of EU membership for Croatia. The SCM will pool from the neighbouring Balkan countries to conduct the analysis, none of which are EU members. Thus, this analysis apply a single case/unit treatment. However, after a lot of struggle I cannot seem to be able to do this with gsynth.

When I try to run gsynth I have my treatment variable (EU) and DV (growth) as well as some control variables, but the error I have been getting is this:

Error in rowSums(Y.ct) : 'x' must be an array of at least two dimensions

library(gsynth)
Registered S3 method overwritten by 'GGally':
method from
+.gg ggplot2

system.time(m1 <- gsynth(gdpprcapitagrowth ~ eu + industry + agriculture + populationgrowth + uneployment + tradeinservices, data = qog, index = c("country", "year"), force = "two-way", EM = TRUE, CV = TRUE, r = c(0, 5), se = TRUE, na.rm = TRUE, inference = "parametric", nboots = 1000, parallel = FALSE))

Error in rowSums(Y.ct) : 'x' must be an array of at least two dimensions
Timing stopped at: 0.055 0.009 0.078

I gathered that this was a problem with with my treatment and its lack of varying dimensions on it, so I tried adding another EU member state (that would receive the treatment) to the analysis, Bulgaria, and with this the gsynth function worked with no errors

My question is then the following: Is gsynth only possible for multiple with treatments with multiple units and not as in my case where only one unit receives treatment? Because this seems to be the case right now

Thank you and apologies for any potential misunderstandings of my question. I am quite new to github and to R

Typo help file - inference option

Great package, Thank you! Found a minor error. The help file says for the inference option: "a string specifying which type of inferential method will be used, either "parametric" or "non-parametric"".
The actual option for the function is "nonparametric".

Individual unit effect inference for matrix completion

@xuyiqing, @liulch,
Is it possible to obtain unit level standard errors when using matrix completion in a two-way format? Thus far, I have not been able to construct them unless using the parametric version of IFE, in which case est.ind is not null.

Also, thank you for building this package, it's wonderful!

Best,
Eddie

The confidence intervals computed on the ATT are not symetric

Hi,

Usually when computing the Confidence intervals around the ATT, the bands shoud be "estimated_effect +- 2*se_bootstrap" and therefore these bands are symmetric around the estimated effects. However, even in some of your examples from: https://yiqingxu.org/software/gsynth/gsynth_examples.html do not have symmetric confidence intervals (I am looking at the MC example).

Could you please provide some help or further explanation on why this happens?

Thanks

Error in `rownames<-`

Hi Xu,

I got the error below when i gsynth on my dataset; not sure what is happening - the panelView plots work.

Error in rownames<-(*tmp*, value = iname[which(out$tr == 1)]) :
attempt to set 'rownames' on an object with no dimensions

Factor-variables as Indices lead to subscript out of bounds error

Seems like there is some out-of-bounds issue, when someone uses a factor variable as index (in my case converting channel_id and yearweek to chars/integers resolved the issue).

> reg.sub <- gsynth(log(subscribers + 0.001) ~ step_dummy,
+                          data = gsynth_panel1, index = c("channel_id","yearweek"),
 force = "two-way",
+                          CV = T, se = T, inference = "parametric", nboots = 1000, parallel = T)
Error in `[<-`(`*tmp*`, c(data[, ob]), 1, value = 1) : 
  subscript out of bounds

Adding autocovariance to gsynth to fix autocorrelated errors

Hi,

I've been using this package for a while and I have to say I am very happy with it. However, I've got a question. I've seen that the paper on NNMCM from Athey et. al, and it says that one drawback of MC-NNM is that it does not take into account the time series nature of the observations. Thus, it is likely that the errors (e_{it}) are correlated over time. However, one can modify the objective function to include an autoregressive coefficient to solve this issue. (Section 8.3 from the paper).

I've been looking at your repository, and I haven't found this correction. I've seen some autocorrelation terms but not used on the objective function (correct me if I'm wrong). My question is then, has anyone looked at this? Has anyone tried to implement it? I would like to help if possible, or at least know if anyone is working on this issue, since it seems quite relevant, especially for long time series with high autocorrelation.

Thanks in advance,

Feliu

Misleading parameter name `cores`

The function gsynth has a parameter called cores, which is defined as

an integer indicating the number of cores to be used in parallel computing.
If not specified, the algorithm will use the maximum number of logical cores
of your computer (warning: this could prevent you from multi-tasking on your computer)

It seems like this is not the number of cores which are used. Instead it defines the number of processes. Specifically, each of those processes can use (at least for some tasks) multiple cores. Fore example, on my test system this parameter was set to 4, but those 4 processes utilised all 32 physical cores.

Optimal cross-validation r<2 with force = two-way

Within the framework of the paper, r is the total number of lambda*f terms. If force = "two-way" is on, I would think that the first and second factors are the unit and time fixed effects, and so r must be 2 or higher, but cross validation finds r=0 or r=1 sometimes. Does the "r" found by cross validation indicate the number of factors IN ADDITION to the unit and fixed effects when force="two-way"?

Error in cumuEff(): object 'D.boot' not found

Dear @xuyiqing, @liulch,
I would like to implement your function for finding cumulative effects (cumEff) but I get the following error when running this line of code. The gsynth object was successfully created.

gsynth_cum<- gsynth::cumuEff(gsynth_object,
                                cumu= TRUE,
                                id = NULL,
                                period = NULL)

Error in gsynth::cumuEff(gsynth_object, cumu = TRUE, id = NULL, period = NULL) :
object 'D.boot' not found

Thanks for any help you may be able to offer and for the terrific package.
-Michael

Want to limit donor pool to units from same state

Hi,

I want to limit donor pool to untreated firms in the same state. Is there a way to do this, beside running the code separately for each state and combine results at the end? Beside being tedious, combining the results would present some challenges.

Thanks,
Markus

Error in inter_fe(Y = Y.co, X = X.co, r, force = force, beta0 = beta0, : Mat::head_cols(): size out of bounds

Dear Professor Xu

Thank you for your work on the generalised synthetic control method.

I am trying to use the gsynth package as specified in the examples, but I am running into an error that I cannot resolve. I have verified that my dataset matches the examples provided in the package.

I am providing the dataset, example code and the error I am getting.

I am using R version 3.4.0 and gsynth version 1.1.4.

Code:

library(gsynth)

data <- readRDS("data.rds")

out <- gsynth(Y ~ D + X1 + X2, data = data, index = c("id", "time"), 
              force = "two-way", CV = TRUE, r = c(0, 5), se = TRUE, inference = "parametric", 
              nboots = 1000, parallel = FALSE)

Error:

> out <- gsynth(Y ~ D + X1 + X2, data = data, index = c("id", "time"), 
+               force = "two-way", CV = TRUE, r = c(0, 5), se = TRUE, inference = "parametric", 
+               nboots = 1000, parallel = FALSE)
Cross-validating ... 
 r = 0; sigma2 = 0.10361; IC = -0.63150; PC = 0.07677; MSPE = 0.09995*
 r = 1; sigma2 = 0.06434; IC = 0.48180; PC = 0.36854; MSPE = 0.10280
 r = 2; sigma2 = 0.04634; IC = 1.72070; PC = 0.49677; MSPE = 0.12504
 r = 3; sigma2 = -0.00000; IC = NaN; PC = -0.00000; MSPE = 0.08032*
 r = 4; sigma2 = -0.00000; IC = NaN; PC = -0.00000; MSPE = Inf

error: Mat::head_cols(): size out of bounds
Error in inter_fe(Y = Y.co, X = X.co, r, force = force, beta0 = beta0,  : 
  Mat::head_cols(): size out of bounds

Data: data.rds.zip

I would greatly appreciate your help.

Error when controls are included in the formula rather than in X

The dataset used in this example is a panel dataset, very much like the sample "simdata."

Issue: Including a control variable X1 in the formula "Y ~ D + X1" leads to the following error:

Error in if (sum(unlist(tapply(data[, Xname[i]], data[, id], var))) == :
missing value where TRUE/FALSE needed

When the same X1 variable is included as "X = X1", the algorithm runs without any issues.

I have looked in the source and found the following lines:
if (p > 0) { for (i in 1:p) { if (sum(is.na(data[, Xname[i]])) > 0) { stop(paste("Missing values in variable \"", Xname[i],"\".", sep = "")) } if (sum(unlist(tapply(data[, Xname[i]], data[, id], var)), na.rm = TRUE) == 0) { stop(paste("Variable \"",Xname[i], "\" is unit-invariant. Try to remove it.", sep = "")) } if (sum(unlist(tapply(data[, Xname[i]], data[, time], var)), na.rm = TRUE) == 0) { stop(paste("Variable \"",Xname[i], "\" is time-invariant. Try to remove it.", sep = "")) } } }

It looks like the error is because the if conditional in the middle shown above resulted in an NA. The conditional must have either a TRUE or FALSE result. However, I don't understand why the X1 of the example "simdata" does not lead to an error, while the X1 of the model causes an error (I am new to R).

X1 of "simdata" is a time and unit-varying variable with the following descriptive statistics:

vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 1500 1.05 1.29 0.97 1.02 1.23 -2.78 5.7 8.48 0.2 0.08 0.03

X1 in the model leading to the error is also a time and unit-varying variable with the following descriptives:

vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 14167 103980.4 342887.5 28098 43736.25 30083.44 40 9848011 9847971 14.03 312.2 2880.8

Related question: When I include the X1 of "simdata" in the "formula," I get different results from including it in "X = ". This is likely a conceptual -side- question but why? The variable X1 in "simdata" is both time and unit-varying, so the results should be the same in both specifications, no? Am I missing something here?

Thanks much!

Attempts to adjust nboot constantly yield errors

Hi,

thank you for implementing this valuable method in R.

However, I'm facing the issue that attempts to adjust the nboot often fail with an error. Please see MCVE below. It would be great if you could take a look at it.

Cheers

MCVE

# set.seed(2247643)
nboots <- 2e2  # works most of the time
nboots <- 2e3  # works most of the time NOT, especially with seed above
gsynth(Y="gini.disp", D="D", X=pred.gini,
       data=sample.dat, parallel=FALSE,
       index=c("id", "time"), force="two-way",
       CV=TRUE, r=c(0, 4), se=TRUE, nboots=nboots)
## may yield:
# Error in eff.boot[, , j] <- boot$eff : 
#   number of items to replace is not a multiple of replacement length

Sample data

sample.dat <- structure(list(id = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 
3, 3, 3, 3, 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 
10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 
9, 9, 9, 9, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8), time = c(9, 10, 11, 12, 
13, 14, 15, 16, 17, 18, 19, 20, 21, 9, 10, 11, 12, 13, 14, 15, 
16, 17, 18, 19, 20, 21, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 
19, 20, 21, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 9, 10, 11, 
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 9, 10, 11, 12, 13, 14, 
15, 16, 17, 18, 19, 20, 21, 9, 10, 11, 12, 13, 14, 15, 16, 17, 
18, 19, 20, 21, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
21, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 9, 10, 
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21), D = c(0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), gini.disp = c(58.4, 58.5, 
58.7, 58.8, 58.9, 58.8, 58.7, 58.6, 58.7, 58.8, 58.8, 58.9, 58.9, 
39.1, 39.3, 39.6, 39.8, 40, 40.2, 40.4, 40.6, 40.7, 40.9, 41, 
41.1, 41.2, 45.4, 45.3, 45.2, 45.2, 45.1, 45, 45, 44.9, 44.8, 
44.6, 44.4, 44.3, 44.2, 39.4, 39.6, 39.7, 39.8, 39.8, 39.8, 39.9, 
39.9, 39.9, 39.9, 39.9, 39.8, 39.8, 36.6, 36.5, 36.6, 36.5, 36.4, 
36.4, 36.4, 36.4, 36.4, 36.5, 36.5, 36.6, 36.6, 48.4, 47.7, 46.9, 
46.1, 45.5, 44.7, 44, 43.6, 43.5, 43.6, 43.5, 43.5, 43.5, 42.6, 
42.3, 42, 41.6, 41.3, 41, 40.7, 40.4, 39.9, 39.5, 39.1, 38.7, 
38.3, 40.2, 40.1, 39.9, 39.7, 39.5, 39.3, 39.2, 39, 38.7, 38.5, 
38.2, 37.9, 37.7, 42.5, 42.7, 42.8, 43, 43.1, 43.3, 43.5, 43.7, 
43.9, 44.1, 44.2, 44.2, 44.2, 40, 40.4, 40.7, 41.1, 41.5, 41.5, 
41.5, 41.5, 41.5, 41.5, 41.5, 41.5, 41.3, 59.3, 59.4, 59.4, 59.5, 
59.6, 59.7, 59.9, 60, 60, 59.8, 59.6, 59.5, 59.4), trade = c(101.841039320292, 
98.9290812021418, 91.924729689918, 87.5250655680957, 91.8357740585774, 
85.8340425151264, 90.9978228872631, 88.5053520573505, 86.3345889171215, 
95.1046388023392, 96.715910335632, 86.6860199052182, 94.8997963219007, 
80.5995432469935, 81.7051040340528, 116.048430162968, 110.045854160811, 
97.4892431746551, 97.2871457139532, 99.6703343472122, 98.1715141146279, 
65.9214438401551, 65.3543222852532, 69.5142256111434, 71.5947385281524, 
75.3778157916824, 48.8972419400753, 48.1922749889095, 53.3090443862273, 
55.9468360286644, 55.1726722640053, 54.132265895729, 59.4770033484288, 
64.4788661639796, 55.2364851257303, 53.8947888046059, 57.5785986473131, 
50.8636415698917, 54.2268646261755, 50.7976821472107, 53.9866926482482, 
59.1618267897056, 59.4180038973489, 60.5340864045186, 58.3277426764957, 
61.596533473438, 67.9148544916014, 71.4962867805158, 78.4871743394128, 
85.6728209004978, 67.91510294823, 75.2476345357777, 132.199131675792, 
130.691257437002, 122.312602490244, 129.778721888857, 119.822340319355, 
110.118531709304, 108.468732616886, 123.246099398259, 127.062861757976, 
120.876451250142, 115.489315893532, 104.42972895159, 113.457073552476, 
70.8751772901036, 71.3159730281056, 60.93863549639, 67.1184036928501, 
41.9008377881176, 50.8424494444496, 51.4662417063174, 57.4479843783725, 
54.3599683102017, 56.4441652527095, 61.9657689679199, 51.6830724947176, 
57.6475200499248, 35.3326795564082, 33.7491637023642, 57.5299628959222, 
35.4243931073053, 38.3858021277704, 45.9060160845621, 45.5880654083465, 
46.872841394771, 41.9127954550172, 40.2953871705296, 39.2134766212099, 
41.4365302397403, 51.277552995909, 79.9794582620079, 77.9051139411665, 
82.4559257711504, 89.5519191091931, 85.3416571939188, 82.390107793166, 
86.9482937078062, 90.2512478803945, 93.9378508972261, 104.075472152244, 
114.354832289326, 93.0168787876722, 104.148633325139, 25.9355690831737, 
25.0134522316518, 23.980867699183, 28.020506467552, 27.4897630463662, 
30.4383675184056, 33.5982316952082, 36.9592732888675, 42.7681664695131, 
48.0583947791253, 49.0265445505002, 43.5326006451782, 47.6404394303252, 
30.043921931244, 36.0247101570245, 32.7490333383822, 35.3299767816294, 
36.2777941575217, 36.5857264653029, 35.4600862458745, 38.9942854848779, 
43.6332857896204, 46.7774166520615, 56.2582682052931, 46.7447497538494, 
45.719821647259, 48.8966176420388, 46.8618860908556, 51.4377739547977, 
54.8016334271381, 59.7646362953014, 51.4018310923647, 51.0780341359982, 
53.1491153902934, 60.2772643253235, 63.6830872879002, 72.865390240783, 
55.4182616022717, 55.9889858083946), credit.gdp = c(12.1559474412172, 
13.8731694622537, 14.7111330843286, 16.5861602106911, 19.2801590248722, 
19.9773621242987, 21.935704704551, 19.7635783205068, 20.4844134528386, 
22.6643360675293, 25.7871707259677, 28.9314710242801, 27.1935874525637, 
9.3588471656594, 12.5620832397761, 13.971491324036, 11.8843912608955, 
12.1495373048323, 12.493048761649, 13.1724893671741, 15.5440688136274, 
11.0935881051932, 14.4884302260337, 15.8819996394551, 15.6580614285644, 
15.2896953808711, 23.9634167841824, 26.5694419300027, 25.7583827680558, 
25.2226866951229, 25.8546018348267, 25.1556752227903, 27.2875160327278, 
26.2768754700489, 22.8883109960388, 23.0449642815856, 25.380611749054, 
25.0216100008749, 27.2281230094577, 41.9922957395565, 45.524117380598, 
48.5920037684968, 42.595142869912, 41.514712192781, 40.5810611288112, 
40.6913982726517, 44.0348960227578, 46.4947439821053, 55.5544935434842, 
60.6939535030437, 63.298478634885, 90.1261045952435, 56.4087879274322, 
56.4371131224897, 56.5017023177118, 56.8527117251502, 57.6954985007251, 
70.6444058466662, 70.9078227589402, 72.8987930395477, 68.6878766043514, 
71.7467361526219, 81.798055590861, 80.077012635807, 85.3551207721711, 
7.10880229410367, 7.96064582503499, 9.07588654704307, 8.4205982311725, 
4.42368375569741, 4.12578635126165, 4.56261391529402, 5.96273880301245, 
6.88566905409057, 8.48420711776938, 9.11346313808723, 10.874779615102, 
13.8296193206838, 2.72451562468195, 2.07182729985576, 2.10803360905412, 
1.60393380038774, 2.00066380829, 2.86272274651729, 3.47359161882558, 
3.34569629280925, 3.38374842848296, 4.32704418518391, 5.57482151429081, 
8.2244969408349, 7.82381885435775, 59.9114127479609, 59.4689151154844, 
59.9890124450877, 61.5108846644512, 62.3029658312412, 60.7479737542157, 
58.9506290134042, 58.291705476344, 57.3279120235501, 57.8508167391409, 
59.8904950079431, 62.2474436408009, 69.1119238119405, 2.94098178373874, 
3.19184158182203, 3.11280258139082, 4.11428871406693, 5.22225830518537, 
6.19017500752826, 7.10723140142027, 7.82538446272157, 9.7900200282604, 
11.4689486744127, 11.9110255359744, 11.2673883569513, 11.7182622748719, 
5.61773653446055, 6.35503596999033, 6.23417489329316, 7.10581101549379, 
7.94713986633, 8.40008730819313, 8.05769990358755, 8.61580595213707, 
10.1087586420267, 10.2315288620039, 13.9010555944997, 11.3939651767063, 
13.3412974682694, 115.167927074881, 131.048239419325, 130.312222875041, 
138.792502825903, 110.718367670577, 115.862201711497, 126.932346081347, 
138.159429134112, 156.976212198837, 160.124784843962, 140.349876469094, 
145.941155530687, 148.981377257943), tcom.expenditures = c(44.9909396841833, 
39.554857245466, 13.9246560846561, 14.0737148399612, 6.76750216076059, 
8.09974204643164, 32.9714655082644, 48.9177489177489, 139.940652818991, 
121.831792162043, 122.222222222222, 83.1780022340517, 97.1278232845244, 
17.3296791151366, 51.1834077635792, 39.8092327249022, 29.5183840297513, 
46.4222660098522, 37.9005864537939, 39.4650789385549, 39.7348578174596, 
46.4332628428242, 50.7346910753857, 48.9306601463602, 54.5890235230154, 
65.474231692618, 23.7558126338013, 47.6844898914732, 88.5325225881043, 
60.9741969457609, 56.7973380472081, 121.39797979798, 63.5798354333396, 
76.276595616334, 86.9341070879351, 38.2148377048496, 38.8345708793487, 
28.0003658339255, 22.3398064018053, 17.0212765957447, 27.3486184597296, 
50.5983455144165, 54.2341871406168, 24.780316344464, 14.5593869731801, 
12.9913871914546, 17.0377741841854, 19.3510990667026, 17.8142852313829, 
21.7629505634585, 19.4388572502947, 16.9884256525352, 35.8793565311533, 
40.8036589349886, 37.6368421052632, 46, 36.0179885527392, 20.7171314741036, 
15.2497710665496, 12.8524350054925, 139.611696300585, 239.343738482923, 
332.593273232957, 200.186131773862, 198.030510839216, 48.1660617171227, 
50.1062731905492, 43.9127575047584, 43.6412224204366, 47.154925974151, 
60.0567681109346, 60.9400094348027, 49.0557583779906, 53.2606139801461, 
46.007802503933, 46.2468902291235, 45.2795519534293, 44.8134683867311, 
38.0493549409312, 36.4940963229338, 44.1956216488544, 47.5805569117872, 
48.0306309209656, 44.4594641819265, 36.1292386128148, 36.6057317747686, 
35.5863179507164, 32.9036967946372, 31.6234246781379, 30.7571688947997, 
35.3607106156828, 44.6, 27.5926666666667, 39.7666666666667, 40.9375668449198, 
52.8315085158151, 51.9364448857994, 36.1369590748939, 21.7050194567775, 
23.1752181500873, 15.5406050955414, 16.0651769087523, 15.7435135035524, 
22.9495551600144, 202.152655897418, 123.016311254854, 12.5584439872826, 
4.31894034754177, 32.5379729586361, 36.5829805779089, 39.5767836903267, 
51.103487719556, 77.6305326891461, 89.511782730033, 87.6889453349354, 
87.8851766652546, 85.1123548450702, 29.9731182795699, 63.3780584056827, 
40.3521057480799, 26.2316949568384, 39.0556537062055, 32.2887634915962, 
35.5603979114751, 23.4316517374623, 34.9136873483129, 38.9161470932355, 
63.1436512641694, 46.7493999586681, 15.8980094866733, 49.5224619738238, 
30.2791277575634, 25.5268876184047, 22.490441562336, 12.2227289013387, 
9.76977392749065, 12.5397345787871, 12.5958315477538, 13.3068636681656, 
13.0779081373232, 14.035710267351, 12.0871502847239, 10.7333516120188
), fem.mortality = c(475.186, 491.194, 507.203, 523.211, 539.22, 
509.391, 479.562, 449.733, 419.904, 390.075, 360.343, 330.611, 
300.88, 278.695, 279.318, 279.94, 280.563, 281.185, 274.368, 
267.551, 260.733, 253.916, 247.098, 244.879, 242.659, 240.439, 
428.528, 434.616, 440.704, 446.792, 452.88, 426.092, 399.304, 
372.515, 345.727, 318.939, 294.401, 269.863, 245.325, 142.93, 
137.941, 132.952, 127.963, 122.973, 115.272, 107.571, 99.87, 
92.168, 84.467, 81.583, 78.7, 75.816, 115.727, 114.941, 114.155, 
113.369, 112.583, 110.82, 109.057, 107.294, 105.531, 103.768, 
102.372, 100.975, 99.578, 491.497, 504.45, 517.402, 530.354, 
543.307, 522.032, 500.757, 479.482, 458.208, 436.933, 403.293, 
369.652, 336.012, 533.122, 522.485, 511.849, 501.212, 490.575, 
480.462, 470.348, 460.234, 450.121, 440.007, 433.448, 426.889, 
420.331, 87.15, 85.409, 83.668, 81.927, 80.185, 79.151, 78.117, 
77.083, 76.049, 75.015, 74.819, 74.624, 74.428, 411.679, 412.226, 
412.773, 413.32, 413.867, 398.814, 383.761, 368.708, 353.655, 
338.602, 320.53, 302.457, 284.385, 503.374, 491.502, 479.63, 
467.759, 455.887, 438.342, 420.798, 403.253, 385.708, 368.163, 
351.349, 334.534, 317.72, 318.746, 346.783, 374.819, 402.855, 
430.891, 438.722, 446.554, 454.385, 462.216, 470.048, 443.013, 
415.978, 388.943), gov.spending = c(30.0691562932227, 27.4109473451781, 
24.9027290058887, 23.4866322167786, 22.3791259879126, 22.0087160576493, 
20.5323439366629, 19.4007450572658, 17.0378523144023, 17.5947805481447, 
20.3512591725774, 21.0895434476663, 19.7565055668383, 10.3241616558742, 
10.8433463882059, 10.1716158733082, 9.72236391765846, 9.87277025091073, 
11.5332032401368, 12.1728118810468, 15.3081652628808, 8.87072220384494, 
8.52494036113545, 8.73165976762738, 7.57424395572255, 7.06949942103097, 
16.2499609195116, 15.7532966549933, 15.0542922556179, 15.9729117514735, 
17.0779999092115, 18.1313185754854, 17.860065964127, 17.3802115523848, 
14.3469988040006, 14.6296114670377, 15.6739794237589, 15.2144716882565, 
14.1690291496481, 15.909932567873, 17.1164300051583, 17.6041341832193, 
17.8871729081631, 17.6402498205155, 17.4233499982418, 17.9050829757389, 
18.5470095999218, 17.8416192248279, 17.5145553101787, 16.7672070508913, 
18.2398264222434, 17.9478323375273, 13.7475945571122, 14.2303708019475, 
14.2517815909722, 13.9259423965107, 14.160138296696, 14.0794924827347, 
14.2020517229511, 14.522658939736, 14.1239287477005, 12.4355925097272, 
12.464556347492, 13.9222500993981, 13.8184876460025, 14.6836338748822, 
13.4459910050491, 14.5778385471568, 15.8088305369244, 10.507191590428, 
9.39791339101711, 9.43958737759919, 10.787801754538, 11.3941159486131, 
10.9939564834833, 13.2280032712649, 15.9463069217763, 14.2314104667119, 
8.9311888689247, 11.465143776952, 14.3331038132408, 13.0207209895975, 
13.9241039189649, 11.826593083486, 10.3634307955356, 9.88617095832977, 
10.0989496155412, 8.64646187591551, 9.65365486831351, 10.5131302216528, 
10.3997147358601, 16.4285570436008, 16.2747374686763, 16.6712533083276, 
16.5715905690391, 17.2266225753311, 17.2011093112602, 16.9223401461433, 
16.9193475197631, 16.708663241378, 16.5074774153175, 16.1341685393665, 
16.6311616777897, 16.6170535013361, 8.22893960121832, 7.83559002503336, 
7.85118007488108, 8.00368234648943, 8.86438840773774, 10.3783153870602, 
11.4759029364499, 11.9180432372987, 11.8898254476192, 13.1092645429996, 
11.3175962184067, 12.3330567444363, 10.3622039009865, 12.8669462699382, 
12.8642588762285, 14.5043243985272, 15.5818448611249, 16.7924696963901, 
15.745053345914, 13.8873022740436, 14.4927633930359, 14.1023117957031, 
12.8930348105166, 11.2108868131478, 9.22514084936743, 9.59420700442812, 
18.9117687991198, 18.5808257053284, 18.3869372434811, 18.5340641441331, 
18.8051903242104, 19.0578880435914, 19.1575642530287, 19.4781894691122, 
18.1535283244536, 17.8140148717565, 18.6579250952803, 19.864480154342, 
20.2296379063367)), row.names = c(1504L, 1505L, 1506L, 1507L, 
1508L, 1509L, 1510L, 1511L, 1512L, 1513L, 1514L, 1515L, 1516L, 
3715L, 3716L, 3717L, 3718L, 3719L, 3720L, 3721L, 3722L, 3723L, 
3724L, 3725L, 3726L, 3727L, 5289L, 5290L, 5291L, 5292L, 5293L, 
5294L, 5295L, 5296L, 5297L, 5298L, 5299L, 5300L, 5301L, 6534L, 
6535L, 6536L, 6537L, 6538L, 6539L, 6540L, 6541L, 6542L, 6543L, 
6544L, 6545L, 6546L, 7329L, 7330L, 7331L, 7332L, 7333L, 7334L, 
7335L, 7336L, 7337L, 7338L, 7339L, 7340L, 7341L, 7431L, 7432L, 
7433L, 7434L, 7435L, 7436L, 7437L, 7438L, 7439L, 7440L, 7441L, 
7442L, 7443L, 9597L, 9598L, 9599L, 9600L, 9601L, 9602L, 9603L, 
9604L, 9605L, 9606L, 9607L, 9608L, 9609L, 10577L, 10578L, 10579L, 
10580L, 10581L, 10582L, 10583L, 10584L, 10585L, 10586L, 10587L, 
10588L, 10589L, 10886L, 10887L, 10888L, 10889L, 10890L, 10891L, 
10892L, 10893L, 10894L, 10895L, 10896L, 10897L, 10898L, 10988L, 
10989L, 10990L, 10991L, 10992L, 10993L, 10994L, 10995L, 10996L, 
10997L, 10998L, 10999L, 11000L, 11699L, 11700L, 11701L, 11702L, 
11703L, 11704L, 11705L, 11706L, 11707L, 11708L, 11709L, 11710L, 
11711L), class = "data.frame")

fail to install on macOS sierra

I couldn't install the package on my mac. Some googling around suggests the problem might be that Apple's clang does not support openMP. But I'm not sure how to fix it. Thanks.

Here is the error message:

> install.packages('gsynth', type = 'source')
Installing package into ‘/Users/paul/Library/R/3.4/library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/gsynth_1.0.6.tar.gz'
Content type 'application/x-gzip' length 100150 bytes (97 KB)
==================================================
downloaded 97 KB

* installing *source* package ‘gsynth’ ...
** package ‘gsynth’ successfully unpacked and MD5 sums checked
** libs
clang++ -std=gnu++11 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I"/Users/paul/Library/R/3.4/library/Rcpp/include" -I"/Users/paul/Library/R/3.4/library/RcppArmadillo/include" -I/usr/local/include  -fopenmp  -fPIC  -Wall -g -O2 -c RcppExports.cpp -o RcppExports.o
clang: error: unsupported option '-fopenmp'
make: *** [RcppExports.o] Error 1
ERROR: compilation failed for package ‘gsynth’
* removing ‘/Users/paul/Library/R/3.4/library/gsynth’
Warning in install.packages :
  installation of package ‘gsynth’ had non-zero exit status

Here is the session info:

> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.4.1 tools_3.4.1    yaml_2.1.14 

trying to set rownames for vector

This is where it breaks, line 531 in the main function:

if (!is.null(out$alpha.tr)) { rownames(out$alpha.tr) <- iname[which(out$tr == 1)] colnames(out$alpha.tr) <- "" }

I'm not sure whether out$alpha.tr should always be a matrix, but it seems to be either a vector or a matrix depending on the if statement here in synth.core

if (max(T0) == T0.min & (!0 %in% I.tr)) { alpha.tr.lv <- colMeans(U.lv) U.tr <- U.tr - matrix(alpha.tr.lv, TT, Ntr, byrow = TRUE) } else { alpha.tr.lv <- sapply(U.lv, mean) U.tr <- U.tr - matrix(alpha.tr.lv, TT, Ntr, byrow = TRUE) }
I'm not into the details of the package or the method enough to be more helpful than this.

setting of nboots does not work

I have tried to setup "boots = " some values, e.g. "nboots = 1000" and "nboots = 100000".
But I got the same results.
What is the problem do you think ?
off course, I setup "se = TRUE".

ATT not included within Standard Error bounds?

Hi,
I have applied the Gsynth function to my dataset.

But, I find it strange that the ATT curve is not always within the confidence interval.
It is not something that I was expecting.

image

My dataset has a staggered treatment (among the treated units, not all treated units begin the treatment in the same year). But some units also leave treatment earlier than other treated.

I thought it can be an explanation of the problem, but the problem stays the same if I reclassify all units as treated all the periods after the first year of treatment.

Please find attached my data frame and my script.

gsynth_problem.zip

Thank you for any explanation or reference that can help me interpret or correct it!
Thanks for an awesome package!

PS: if I run the analysis with the MC estimator, the problem disappears.

Error when r = 0 : Attempt to set 'rownames' on an object with no dimensions

I am running into the same error message as user fickse here: cran/gsynth#1

When I try to set r = 0 in order to compare gsynth to diff-in-diff or when r is set to zero in the CV-step, I get the error message

Error in rownames<-(*tmp*, value = c(101, 102, 103, 104, 105)) :
attempt to set 'rownames' on an object with no dimensions

I am copying fickse's example below:

data(gsynth)

out <- gsynth(Y ~ D + X1 + X2, data = simdata, index = c("id","time"), force = "two-way", CV = FALSE, r = 0, se = TRUE, inference = "parametric", nboots = 1000, parallel = FALSE)

"All treated units have been removed" error

Hi,
I have data from 2008 to 2015 and pre-treatment period is 2008-2010. I get the following error message.

Error in gsynth.default(formula = NULL, data = data, Y = Yname, D = Dname, :
All treated units have been removed

Any suggestion? Thanks in advance!
Syed

cumuEff and option "period"

I am using version 1.16 of gsynth and a monthly panel that includes 48 periods (with gaps). I was trying to calculate the average treatment effect for a sub-group with cumuEff. Initially, I used cumuEff with period = c(0,12) but without the id option, expecting to get the average treatment effect for all groups, but limited to 12 post-treatment periods. However, what I noticed was that instead of periods 0 to 12 I got the ATT for periods -4 to 8. Trying different dependent variables, I found that sometimes I would get the correct period 0 to 12, but other times also larger offsets (e.g., -10 to 2). Where are these offsets coming from? I am sure I overlooked something.

out <- gsynth(Y ~ D, data = data_collapsed, EM = TRUE, index = c("groups","month"), force = "two-way", CV = TRUE, r = c(0, 5), se = TRUE, inference = "parametric", nboots = 1000, parallel = FALSE, min.T0 = 6, cl = "city")

cumu2 <- cumuEff(out, cumu = FALSE, period = c(0,12))

error occurred at simulating error step

Hi,
We ran into the following error with some of our gsynth model:
Simulating errors ...Error in { : task 602 failed - "'data' must be of a vector type, was 'NULL'"

In our study, we have lots of treated units with varying treatment timing. So we just tried to run gsynth on the entire dataset and a subset only with treated units at a certain period. The error only occurs when using the subset (the 2nd model in the sample code).

I also attached the sample data & code to reproduce the error. The code:

test1 <- readRDS("tmpdata/testdata.RDS")

out1 <- gsynth(dv1 ~ treatment + covar1 + covar2 + covar3 + covar4 + covar5 + covar6, data = test1, index = c("id", "TimePeriod"), na.rm = TRUE, force = "two-way", CV = TRUE, r = c(0,5), se = TRUE, inference = "nonparametric", min.T0 = 7, seed = 1, nboots = 1000, parallel = TRUE, cores = 4)

test2 <- test1 %>% group_by(id) %>% mutate(check = sum(treatment)) %>% ungroup() %>% filter(check == 7 | check == 0) %>% select(-check)

out2 <- gsynth(dv1 ~ treatment + covar1 + covar2 + covar3 + covar4 + covar5 + covar6, data = test2, index = c("id", "TimePeriod"), na.rm = TRUE, force = "two-way", CV = TRUE, r = c(0,5), se = TRUE, inference = "parametric", min.T0 = 7, seed = 1, nboots = 1000, parallel = TRUE, cores = 4)

I found the error seems to be related to a particular covariate and random number generator: when I remove "covar6" from the model, the error disappears, and also I ran multiple times, sometimes it went through...

Also, I'm on PC Windows 10 with R version is 4.0.0. and gsynth 1.0.9

Many thanks!

Dee

testdata.zip

Option `weight` triggers an error for staggered design

Below is a minimum example. First, load the turout data and add a weighting variable of all 1:

library(gsynth)
data(gsynth)
turnout$W = 1

The following code (without weight) work as expected:

out <- gsynth(turnout ~ policy_edr, data = turnout, EM = FALSE, MC = FALSE, 
  index = c("abb", "year"), se = FALSE)
#> Cross-validating ... 
#>  r = 0; sigma2 = 93.28854; IC = 4.53570; MSPE = 50.99510
#>  r = 1; sigma2 = 33.21362; IC = 3.95883; MSPE = 47.57511
#>  r = 2; sigma2 = 10.95689; IC = 3.29076; MSPE = 10.56376*
#>  r = 3; sigma2 = 7.92021; IC = 3.39219; MSPE = 12.33878
#>  r = 4; sigma2 = 5.74782; IC = 3.48262; MSPE = 14.87479
#>  r = 5; sigma2 = 4.16885; IC = 3.55753; MSPE = 16.83409
#> 
#>  r* = 2

Allowing weight yields an error about a missing object: object 'Y.tr.cnt' not found:

out <- gsynth(turnout ~ policy_edr, data = turnout, weight = "W", EM = FALSE, 
  MC = FALSE, index = c("abb", "year"), se = FALSE)
#> Cross-validating ... 
#>  r = 0; sigma2 = 93.28854; IC = 4.53570; MSPE = 50.99510
#>  r = 1; sigma2 = 33.21362; IC = 3.95883; MSPE = 47.57511
#>  r = 2; sigma2 = 10.95689; IC = 3.29076; MSPE = 10.56376*
#>  r = 3; sigma2 = 7.92021; IC = 3.39219; MSPE = 12.33878
#>  r = 4; sigma2 = 5.74782; IC = 3.48262; MSPE = 14.87479
#>  r = 5; sigma2 = 4.16885; IC = 3.55753; MSPE = 16.83409
#> 
#>  r* = 2
#> Error in synth.core(Y = Y, X = X, D = D, I = I, W = W, r = r, r.end = r.end, : object 'Y.tr.cnt' not found

I got the same error if I turned on the EM or MC option. Will submit a PR soon to fix the issue.

unit -invariant variable

Hi,

I am building out a model where one of my covariates, elevation, is fixed and does not vary with time as the outcome and some other covariates (e.g. pop?).

I created a long structure data format and for the column with the elevation value it repeats for each year there is an observation. I, however, get the following error:
"Error in gsynth.default(formula = NULL, data = data, Y = Yname, D = Dname, : Variable "elevation" is unit-invariant. Try to remove it. Timing stopped at: 10.85 0.32 13.47"

Any guidance on the best way to include these time-invariate covariates would be greatly appreciated.

Anand

Error object 'eff.cnt' not found when using normalization

Even a basic regression like:

gsynth_res <- gsynth(y ~ step_dummy, data = gsynth_panel, index = c("channel_id","date"))

fails, when I set the option normalize to True. The output indicates a unspecified variable:

Parallel computing ...
Cross-validating ... 
 r = 0; sigma2 = 0.05228; IC = -2.95122; MSPE = 0.00071
 r = 1; sigma2 = 0.02246; IC = -3.62720; MSPE = 0.00009
 r = 2; sigma2 = 0.00185; IC = -5.95540; MSPE = 0.00000
 r = 3; sigma2 = 0.00077; IC = -6.66797; MSPE = 0.00000*
 r = 4; sigma2 = 0.00038; IC = -7.20358; MSPE = 0.00000
 r = 5; sigma2 = 0.00022; IC = -7.58177; MSPE = 0.00000

 r* = 3

Error in synth.core(Y = Y, X = X, D = D, I = I, W = W, r = r, r.end = r.end,  : 
  object 'eff.cnt' not found

ps: I am using the newest version (github-master).

Error with using cumuEff function

When I using cumuEff function, I come across an error: Error in apply(D, 2, function(vec) { : dim(X) must have a positive length
In my dataset, there is only one treated unit. How can I fix this?

Is it possible to include factor variable as matches?

When I try to incorporate factor variables to gsynth, i get the following error:

gsynth::gsynth( formula= as.formula(paste0("T14_Tot_Op", " ~ ", "proac_rep_et +", "perc_white + B19013_001E +perc_rented_occupied_hous_units + perc_us_cit + SAEPOVRTALL_PT + B19083_001E + B25064_001E + B19301_001E + perc_less_than_highscool")), data = output_stata_PR, na.rm=T, index = c("FIPS","year_quart"), se = TRUE, inference = "nonparametric", r = 0, CV = T, force = "two-way", nboots = 1000, seed = 02139)

Error in if (PC < min(CV.out[, "PC"])) { : argument is of length zero

The rest of the covariates works well, but only urbrural is composed by 6 categories: Large Central Metro, Large Fringe Metro, , Medium Metro, Micropolitan, Noncore and Small Metro.

Error in {:

I get this strange error:

Simulating errors ...Error in { : 
  task 5 failed - "'data' must be of a vector type, was 'NULL'"

I can reproduce it, but I don't know how to debug it properly.

I use R: 3.4.1 on Linux and the newest CRAN version of this package.

Error: parallel computing

I have an issue using parallel computing. The gsynth function works perfectly fine when running without parallel computing. When I set parallel = T, the following error occurs:
"Error in { : task 1 failed - "could not find function "ginv"""

It happens at the stage of error simulation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.