jkcshea / ivmte

An R package for implementing the method in Mogstad, Santos, and Torgovitsky (2018, Econometrica).
GNU General Public License v3.0
18 stars 2 forks source link

Error when not including any functions of u #185

Closed a-torgovitsky closed 4 years ago

a-torgovitsky commented 4 years ago
library("ivmte")
results <- ivmte(data = AE,
                 target = "att",
                 m0 = ~ yob,
                 m1 = ~ 1,
                 ivlike = worked ~ morekids + samesex + morekids*samesex,
                 propensity = morekids ~ samesex,
                 noisy = FALSE)

gives me

LP solver: Gurobi ('gurobi')

Obtaining propensity scores...

Generating target moments...
    Integrating terms for control group...
    Integrating terms for treated group...

Generating IV-like moments...
    Moment 1...
    Moment 2...
    Moment 3...
    Moment 4...
    Independent moments: 4 

Performing audit procedure...
    Generating initial constraint grid...
Error in data.frame(..., check.names = FALSE) : 
  arguments imply differing number of rows: 0, 2

There's nothing about the methodology that should prevent this specification though. If I add a u to m0 (but curiously, still leave m1 as constant), then there's no problem

library("ivmte")
results <- ivmte(data = AE,
                 target = "att",
                 m0 = ~ u + yob,
                 m1 = ~ 1,
                 ivlike = worked ~ morekids + samesex + morekids*samesex,
                 propensity = morekids ~ samesex,
                 noisy = FALSE)

yields


Bounds on the target parameter: [-0.1697313, -0.08517579]
Audit terminated successfully after 1 round 
jkcshea commented 4 years ago

Done! This should run properly now.

In the previously problematic example you posted, I now get this:

LP solver: Gurobi ('gurobi')

Obtaining propensity scores...

Generating target moments...
    Integrating terms for control group...
    Integrating terms for treated group...

Generating IV-like moments...
    Moment 1...
    Moment 2...
    Moment 3...
    Moment 4...
    Independent moments: 4 

Performing audit procedure...
    Generating initial constraint grid...

    Audit count: 1
    Minimum criterion: 0.004206539
    Obtaining bounds...
    Violations: 0
    Audit finished.

Bounds on the target parameter: [-0.1433856, -0.1428222]

The code can now also handle the case where both m0 and m1 are just intercept terms.

> ## Run only with intercept terms, with trivial IV-like estimands
> ivmte(data = AE,
+       target = "att",
+       m0 = ~ 1,
+       m1 = ~ 1,
+       ivlike = worked ~ morekids,
+       propensity = morekids ~ samesex,
+       noisy = TRUE)

LP solver: Gurobi ('gurobi')

Obtaining propensity scores...

Generating target moments...
    Integrating terms for control group...
    Integrating terms for treated group...

Generating IV-like moments...
    Moment 1...
    Moment 2...
    Independent moments: 2 

Performing audit procedure...
    Generating initial constraint grid...

    Audit count: 1
    Minimum criterion: 0
    Obtaining bounds...
    Violations: 0
    Audit finished.

Bounds on the target parameter: [-0.1422836, -0.1422836]

> ## Check that it matches the basic difference in means
> mean(AE[AE$morekids == 1, ]$worked) - mean(AE[AE$morekids == 0, ]$worked)
[1] -0.1422836

> ## Run with only intercept, but non-trivial IV-like estimands so that
> ## minimum criterion is violated---bounds no longer match simple
> ## difference in means.
> ivmte(data = AE,
+       target = "atu",
+       m0 = ~ 1,
+       m1 = ~ 1,
+       ivlike = worked ~ morekids + samesex + morekids*samesex,
+       propensity = morekids ~ samesex,
+       noisy = FALSE)

LP solver: Gurobi ('gurobi')

Obtaining propensity scores...

Generating target moments...
    Integrating terms for control group...
    Integrating terms for treated group...

Generating IV-like moments...
    Moment 1...
    Moment 2...
    Moment 3...
    Moment 4...
    Independent moments: 4 

Performing audit procedure...
    Generating initial constraint grid...

    Audit count: 1
    Minimum criterion: 0.004206539
    Obtaining bounds...
    Violations: 0
    Audit finished.

Bounds on the target parameter: [-0.1431494, -0.1431494]
a-torgovitsky commented 4 years ago

Looks good, thanks!