Hi @technocrat ,
Thank you for your response.
Yes, i apologize for the lack of a data example - I'm rather new here!
Treated firms have ETS == 1 and potential controls have ETS == 0. In the listed example, row 8 is a treated unit.
With genmatch i find potential matches by giving weights to covariates over the full sample. Within these potential matches, i want to match exactly on: : b_pat9903, bvd_sector_num & last_available_year. For last_avail_year i want to allow that a potential control units varies with +-1 from the treated. I.e., potential control units that isn't similar to any treated unit, on the 3 variables, should be dropped, and treated units where no controls are similar on the 3 variables should be dropped.
In the listed example, obs. 3 and 8 would be matched since they are equal on b_pat9903 and bvd_sector_num, and within +-1 on last_avail_year. Every other obs. should be dropped.
I hope this properly explains my problem, and that the reprex provided is sufficient - if not please let me know.
Once again, thank you for your time
## Dataex
head(AT, 10)[, c('bvd_sector_num', 'incorporation_year', 'revenue_last', 'ETS', 'last_avail_year', 'green_pat9903', 'b_green_pat9903', 'pat9903', 'b_pat9903')]
datapasta::df_paste(head(AT, 10)[, c('bvd_sector_num', 'incorporation_year', 'revenue_last', 'ETS', 'last_avail_year', 'green_pat9903', 'b_green_pat9903', 'pat9903', 'b_pat9903')])
data.frame(
bvd_sector_num = c(13, 28, 21, 15, 4, 15, 1, 21, 28, 25),
incorporation_year = c(1939,1989,1988,1973,
1970,1979,1996,1985,1989,1992),
revenue_last = c(160247.04721,7480.82644,
1219,2114709.63818,2479725.69383,271142.60536,457,
496.5,2543.55,2890),
ETS = c(0, 0, 0, 0, 0, 0, 0, 1, 0, 0),
last_avail_year = c(2021,2021,2021,2021,
2021,2021,2023,2022,2001,2020),
green_pat9903 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
b_green_pat9903 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
pat9903 = c(0, 0, 0, 35, 0, 28, 0, 0, 0, 0),
b_pat9903 = c(0, 0, 0, 1, 0, 1, 0, 0, 0, 0)
)
#> bvd_sector_num incorporation_year revenue_last ETS last_avail_year
#> 1 13 1939 160247.047 0 2021
#> 2 28 1989 7480.826 0 2021
#> 3 21 1988 1219.000 0 2021
#> 4 15 1973 2114709.638 0 2021
#> 5 4 1970 2479725.694 0 2021
#> 6 15 1979 271142.605 0 2021
#> 7 1 1996 457.000 0 2023
#> 8 21 1985 496.500 1 2022
#> 9 28 1989 2543.550 0 2001
#> 10 25 1992 2890.000 0 2020
#> green_pat9903 b_green_pat9903 pat9903 b_pat9903
#> 1 0 0 0 0
#> 2 0 0 0 0
#> 3 0 0 0 0
#> 4 0 0 35 1
#> 5 0 0 0 0
#> 6 0 0 28 1
#> 7 0 0 0 0
#> 8 0 0 0 0
#> 9 0 0 0 0
#> 10 0 0 0 0
# Code
zs <- (AT$ETS)
Y <- (AT$employees0104)
Xs <- data.frame(AT$bvd_sector_num, AT$last_avail_year, AT$incorporation_year, AT$revenue_last, AT$green_pat9903, AT$b_green_pat9903, AT$pat9903, AT$b_pat9903)
balance_matrix <- Xs
gen <- GenMatch(Tr=zs, X=Xs, BalanceMatrix=balance_matrix, pop.size=500, fit.func="pvals")
exact <- rep(FALSE, length(colnames(Xs)))
exact[grep("b_pat9903", colnames(Xs))] <- TRUE
exact[grep("bvd_sector_num", colnames(Xs))] <- TRUE
exact[grep("last_avail_year", colnames(Xs))] <- abs(Xs$last_avail_year - AT$last_avail_year) <= 1
m <- Match(Y=Y, Tr=zs, X=Xs, Weight.matrix=gen, exact = exact)