bcallaway11 / did

Difference in Differences with Multiple Periods, website: https://bcallaway11.github.io/did
288 stars 92 forks source link

Help Extracting Aggte Results to an Image/ Export #88

Closed DonQuixote1997 closed 2 years ago

DonQuixote1997 commented 2 years ago

Hello all,

I have been trying to use msummary and stargazer packages to try to export my results to a nice image to be used on my thesis paper but have gotten errors that these packages do not work with the did package.

Is there a different package or function that will allow me to do this?

Thanks!

bcallaway11 commented 2 years ago

I don't have much experience with stargazer, but I think that you should be able to use our results with the modelsummary package (there is a function called msummary from that package, so I think that is what you mean here, but I'm not 100% sure). Something like the following code seems to work for me:

library(did)
library(modelsummary)
data(mpdta)
out <- att_gt(yname = "lemp",
              gname = "first.treat",
              idname = "countyreal",
              tname = "year",
              xformla = ~1,
              data = mpdta,
              est_method = "reg"
              )
agg_dyn <- aggte(out, type="dynamic")
modelsummary(agg_dyn)

Let me know if that works ok for you. Thanks!

DonQuixote1997 commented 2 years ago

Thanks for the quick reply!

My code is: install.packages("did") library(did) library(modelsummary)

state_data <- read.csv("CrimeRateStates.csv", stringsAsFactors=FALSE)

first murderperthousand

Murder_attgt <- att_gt (yname = "Murderperthousand", tname = "Year", idname = "Stateid", gname = "first.treat", xformla = ~1, data = state_data) summary(Murder_attgt) ggdid(Murder_attgt)

group specific effects for murders per thousand

Murder_agg.gs <- aggte(Murder_attgt, type = 'group') summary(Murder_agg.gs) ggdid(Murder_agg.gs, title= "Average Effect by Group in the case of Murders per Thousand People") modelsummary(Murder_agg.gs)

And it produced the error: Error in get_estimates(models[[j]], conf_level = conf_level, vcov = vcov[[i]], : `modelsummary could not extract the required information from a model of class "AGGTEobj". The package tried a sequence of 2 helper functions to extract estimates:

broom::tidy(model) parameters::parameters(model)

To draw a table, one of these commands must return a data.frame with a column named "term". The modelsummary website explains how to summarize unsupported models or add support for new models yourself:

https://vincentarelbundock.github.io/modelsummary/articles/modelsummary.html

These errors messages were generated during extraction: broom::tidy(model) did not return a valid data.frame. parameters::parameters(model) did not return a valid data.frame. In addition: Warning message: In get_gof(models[[j]], vcov_type[[i]], ...) : `modelsummary could not extract goodness-of-fit statistics from a model of class "AGGTEobj". The package tried a sequence of 2 helper functions:

broom::glance(model) performance::model_performance(model)

One of these functions must return a one-row data.frame. The modelsummary website explains how to summarize unsupported models or add support for new models yourself:

https://vincentarelbundock.github.io/modelsummary/articles/modelsummary.html

pedrohcgs commented 2 years ago

Are you using the Github version of the package? If not, please try it.

On Wed, Dec 1, 2021 at 21:10 DonQuixote1997 @.***> wrote:

Thanks for the quick reply!

My code is: install.packages("did") library(did) library(modelsummary)

state_data <- read.csv("CrimeRateStates.csv", stringsAsFactors=FALSE)

first murderperthousand

Murder_attgt <- att_gt (yname = "Murderperthousand", tname = "Year", idname = "Stateid", gname = "first.treat", xformla = ~1, data = state_data) summary(Murder_attgt) ggdid(Murder_attgt)

group specific effects for murders per thousand

Murder_agg.gs <- aggte(Murder_attgt, type = 'group') summary(Murder_agg.gs) ggdid(Murder_agg.gs, title= "Average Effect by Group in the case of Murders per Thousand People") modelsummary(Murder_agg.gs)

And it produced the error: Error in get_estimates(models[[j]], conf_level = conf_level, vcov = vcov[[i]], : `modelsummary could not extract the required information from a model of class "AGGTEobj". The package tried a sequence of 2 helper functions to extract estimates:

broom::tidy(model) parameters::parameters(model)

To draw a table, one of these commands must return a data.frame with a column named "term". The modelsummary website explains how to summarize unsupported models or add support for new models yourself:

https://vincentarelbundock.github.io/modelsummary/articles/modelsummary.html

These errors messages were generated during extraction: broom::tidy(model) did not return a valid data.frame. parameters::parameters(model) did not return a valid data.frame. In addition: Warning message: In get_gof(models[[j]], vcov_type[[i]], ...) : `modelsummary could not extract goodness-of-fit statistics from a model of class "AGGTEobj". The package tried a sequence of 2 helper functions:

broom::glance(model) performance::model_performance(model)

One of these functions must return a one-row data.frame. The modelsummary website explains how to summarize unsupported models or add support for new models yourself:

https://vincentarelbundock.github.io/modelsummary/articles/modelsummary.html

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bcallaway11/did/issues/88#issuecomment-984251729, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABE7344BLRRMSINTNKGISDTUO3PRFANCNFSM5JF6BOFA .

--

Pedro H. C. Sant'Anna Department of Economics Vanderbilt University 615-875-8448 (phone) @.*** https://pedrohcgs.github.io

bcallaway11 commented 2 years ago

I think Pedro is probably right, please try removing the version of did that you have installed and trying:

devtools::install_github("bcallaway11/did")

I think that version should work for you (please let me know if you still have issues though).

The version of our code on CRAN is starting to lag behind what's on GitHub, but we should have an update to CRAN hopefully very soon.

Brant

DonQuixote1997 commented 2 years ago

Thanks for the update.

Running into installation issues with the package: devtools::install_github("bcallaway11/did") Skipping install of 'did' from a github remote, the SHA1 (08e3928a) has not changed since last install. Use force = TRUE to force installation

Did download Rtools4 on windows to see if it helps?

DonQuixote1997 commented 2 years ago

I updated R as well and when using the package from devtools::install_github("bcallaway11/did") the did functions are not recognized.

Error in att_gt(yname = "Murderperthousand", tname = "Year", idname = "Stateid", : could not find function "att_gt"

pedrohcgs commented 2 years ago

These are probably not related to the package.

On Wed, Dec 1, 2021 at 22:47 DonQuixote1997 @.***> wrote:

I updated R as well and when using the package from devtools::install_github("bcallaway11/did") the did functions are not recognized.

Error in att_gt(yname = "Murderperthousand", tname = "Year", idname = "Stateid", : could not find function "att_gt"

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/bcallaway11/did/issues/88#issuecomment-984289476, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABE7342N6ZR4RTD6MPQXAG3UO326VANCNFSM5JF6BOFA .

--

Pedro H. C. Sant'Anna Department of Economics Vanderbilt University 615-875-8448 (phone) @.*** https://pedrohcgs.github.io

DonQuixote1997 commented 2 years ago

I am confused.

Is att_gt, aggte, and ggdid not part of did package?

pedrohcgs commented 2 years ago

What I meant is that the issues you are facing are not related to our package. Probably related to some machine-specific issue.

Unfortunately we can’t support all these as we dont have the bandwidth to do so.

On Wed, Dec 1, 2021 at 22:53 DonQuixote1997 @.***> wrote:

I am confused.

Is att_gt, aggte, and ggdid not part of did package?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/bcallaway11/did/issues/88#issuecomment-984291618, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABE7345ONPUTVCP7HGJT4NTUO33UVANCNFSM5JF6BOFA .

--

Pedro H. C. Sant'Anna Department of Economics Vanderbilt University 615-875-8448 (phone) @.*** https://pedrohcgs.github.io

zthab commented 2 years ago

Hi! i was wondering if this feature could be incorporated into the AGGTE object class for the 'simple' type of output. I tested it with my own data and with the mpdta from the package, and I was able to use model summary to produce tables for all other types (group, calendar, and dynamic) while 'simple' threw an error. I dont believe that this is a problem with how i created the aggte object with type simple, as it prints outside of the modelsummary statement perfectly fine. I've attached the following chunk of code that should reproduce what I'm talking about.


data(mpdta)
mw.attgt <- att_gt(yname = "lemp",
                   gname = "first.treat",
                   idname = "countyreal",
                   tname = "year",
                   xformla = ~1,
                   data = mpdta,
)
modelsummary(mw.attgt)
mw.dyn <- aggte(mw.attgt, type='dynamic')
modelsummary(mw.dyn) #works
mw.grp <- aggte(mw.attgt, type='group')
modelsummary(mw.grp) #works 
mw.cal <- aggte(mw.attgt, type='calendar')
modelsummary(mw.cal) #works 
mw.simp <- aggte(mw.attgt, type='simple')
print(mw.simp) #works
modelsummary(mw.simp) #doesnt work 

Best, Zahra

bcallaway11 commented 2 years ago

Hi @zthab, you are right about this. I created a new issue for this: #118. I'll comment there.