synth-inference / synthdid

Synthetic difference in differences
https://synth-inference.github.io/synthdid
BSD 3-Clause "New" or "Revised" License
262 stars 98 forks source link

Error in apply(Y[1:N0, 1:T0], 1, diff) : dim(X) must have a positive length #78

Open cyfreya opened 2 years ago

cyfreya commented 2 years ago

when i used my data, there is an error "Error in apply(Y[1:N0, 1:T0], 1, diff) : dim(X) must have a positive length',how to solve it, thank you

davidahirshberg commented 2 years ago

What are N0, T0, and dim(Y)? On Jan 5, 2022, 6:58 AM -0500, cyfreya @.***>, wrote:

when i used my data, there is an error "Error in apply(Y[1:N0, 1:T0], 1, diff) : dim(X) must have a positive length',how to solve it, thank you — Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you are subscribed to this thread.Message ID: @.***>

cyfreya commented 2 years ago

Thank you answer my question. In my study , n0 is 2178 (the number of control units), t0 is 1(the number of pre-treatment time steps), dim Y = 2248,3Sent from my Huawei phone-------- Original message --------From: davidahirshberg @.>Date: Wed, Jan 5, 2022, 20:22To: synth-inference/synthdid @.>Cc: cyfreya @.>, Author @.>Subject: Re: [synth-inference/synthdid] Error in apply(Y[1:N0, 1:T0], 1, diff) : dim(X) must have a positive length (Issue #78)

What are N0, T0, and dim(Y)?

On Jan 5, 2022, 6:58 AM -0500, cyfreya @.***>, wrote:

when i used my data, there is an error "Error in apply(Y[1:N0, 1:T0], 1, diff) : dim(X) must have a positive length',how to solve it, thank you

Reply to this email directly, view it on GitHub, or unsubscribe.

Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

—Reply to this email directly, view it on GitHub, or unsubscribe.Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you authored the thread.Message ID: @.***>

davidahirshberg commented 2 years ago

I see. Our code doesn’t work if you have only one pre-treatment time step.

The error you’re seeing is happening where it attempts to estimate the noise level by looking at the first-differenced pre-treatment outcomes — because there is only one pre-treatment time step, you can’t take first differences.

While we could tweak the code a bit to make it work in this case, synthetic control methods aren’t really appropriate for settings with one pre-treatment time step. With only one pre-treatment observation for each unit, there’s not really enough information available to learn useful synthetic control weights.

Best, Skip On Jan 5, 2022, 8:16 PM -0500, cyfreya @.***>, wrote:

Thank you answer my question. In my study , n0 is 2178 (the number of control units), t0 is 1(the number of pre-treatment time steps), dim Y = 2248,3Sent from my Huawei phone-------- Original message --------From: davidahirshberg @.>Date: Wed, Jan 5, 2022, 20:22To: synth-inference/synthdid @.>Cc: cyfreya @.>, Author @.>Subject: Re: [synth-inference/synthdid] Error in apply(Y[1:N0, 1:T0], 1, diff) : dim(X) must have a positive length (Issue #78) What are N0, T0, and dim(Y)? On Jan 5, 2022, 6:58 AM -0500, cyfreya @.***>, wrote:

when i used my data, there is an error "Error in apply(Y[1:N0, 1:T0], 1, diff) : dim(X) must have a positive length',how to solve it, thank you — Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you are subscribed to this thread.Message ID: @.***>

—Reply to this email directly, view it on GitHub, or unsubscribe.Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you authored the thread.Message ID: @.> — Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.Message ID: @.>

cyfreya commented 2 years ago

Thank you very much! I will appreciate it if you give some suggestions for the question: There are two ways to add covariates: first is adding covariates as an array when using the synthdid_estimate(), second is using xsynthdid. I want to choose the unit and time weights based on covariates, should i use the second way,  and how many covariables can I add? Can I compare the coefficient by the standard deviation and the critical value of a normal distribution?

Sincerely yours

------------------ 原始邮件 ------------------ 发件人: "synth-inference/synthdid" @.>; 发送时间: 2022年1月6日(星期四) 上午9:27 @.>; @.**@.>; 主题: Re: [synth-inference/synthdid] Error in apply(Y[1:N0, 1:T0], 1, diff) : dim(X) must have a positive length (Issue #78)

I see. Our code doesn’t work if you have only one pre-treatment time step.

The error you’re seeing is happening where it attempts to estimate the noise level by looking at the first-differenced pre-treatment outcomes — because there is only one pre-treatment time step, you can’t take first differences.

While we could tweak the code a bit to make it work in this case, synthetic control methods aren’t really appropriate for settings with one pre-treatment time step. With only one pre-treatment observation for each unit, there’s not really enough information available to learn useful synthetic control weights.

Best, Skip On Jan 5, 2022, 8:16 PM -0500, cyfreya @.>, wrote: > Thank you answer my question. In my study , n0 is 2178 (the number of control units), t0 is 1(the number of pre-treatment time steps), dim Y = 2248,3Sent from my Huawei phone-------- Original message --------From: davidahirshberg @.>Date: Wed, Jan 5, 2022, 20:22To: synth-inference/synthdid @.>Cc: cyfreya @.>, Author @.>Subject: Re: [synth-inference/synthdid] Error in apply(Y[1:N0, 1:T0], 1, diff) : dim(X) must have a positive length (Issue #78) > What are N0, T0, and dim(Y)? > On Jan 5, 2022, 6:58 AM -0500, cyfreya @.>, wrote: > > when i used my data, there is an error "Error in apply(Y[1:N0, 1:T0], 1, diff) : dim(X) must have a positive length',how to solve it, thank you > > — > > Reply to this email directly, view it on GitHub, or unsubscribe. > > Triage notifications on the go with GitHub Mobile for iOS or Android. > > You are receiving this because you are subscribed to this thread.Message ID: @.> > > > —Reply to this email directly, view it on GitHub, or unsubscribe.Triage notifications on the go with GitHub Mobile for iOS or Android. > You are receiving this because you authored the thread.Message ID: @.> > — > Reply to this email directly, view it on GitHub, or unsubscribe. > Triage notifications on the go with GitHub Mobile for iOS or Android. > You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you authored the thread.Message ID: @.***>

davidahirshberg commented 2 years ago

Neither synthdid nor xsynthdid estimates weights that are based on covariates.

On Thu, Jan 6, 2022 at 1:45 AM cyfreya @.***> wrote:

Thank you very much! I will appreciate it if you give some suggestions for the question: There are two ways to add covariates: first is adding covariates as an array when using the synthdid_estimate(), second is using xsynthdid. I want to choose the unit and time weights based on covariates, should i use the second way,  and how many covariables can I add? Can I compare the coefficient by the standard deviation and the critical value of a normal distribution?

Sincerely yours

------------------ 原始邮件 ------------------ 发件人: "synth-inference/synthdid" @.>; 发送时间: 2022年1月6日(星期四) 上午9:27 @.>; @.**@.>; 主题: Re: [synth-inference/synthdid] Error in apply(Y[1:N0, 1:T0], 1, diff) : dim(X) must have a positive length (Issue #78)

I see. Our code doesn’t work if you have only one pre-treatment time step.

The error you’re seeing is happening where it attempts to estimate the noise level by looking at the first-differenced pre-treatment outcomes — because there is only one pre-treatment time step, you can’t take first differences.

While we could tweak the code a bit to make it work in this case, synthetic control methods aren’t really appropriate for settings with one pre-treatment time step. With only one pre-treatment observation for each unit, there’s not really enough information available to learn useful synthetic control weights.

Best, Skip On Jan 5, 2022, 8:16 PM -0500, cyfreya @.>, wrote: > Thank you answer my question. In my study , n0 is 2178 (the number of control units), t0 is 1(the number of pre-treatment time steps), dim Y = 2248,3Sent from my Huawei phone-------- Original message --------From: davidahirshberg @.>Date: Wed, Jan 5, 2022, 20:22To: synth-inference/synthdid @.>Cc: cyfreya @.>, Author @.***>Subject: Re: [synth-inference/synthdid] Error in apply(Y[1:N0, 1:T0], 1, diff) : dim(X) must have a positive length (Issue

78)

> What are N0, T0, and dim(Y)? > On Jan 5, 2022, 6:58 AM -0500, cyfreya @.>, wrote: > > when i used my data, there is an error "Error in apply(Y[1:N0, 1:T0], 1, diff) : dim(X) must have a positive length',how to solve it, thank you > > — > > Reply to this email directly, view it on GitHub, or unsubscribe. > > Triage notifications on the go with GitHub Mobile for iOS or Android. > > You are receiving this because you are subscribed to this thread.Message ID: @.> > > > —Reply to this email directly, view it on GitHub, or unsubscribe.Triage notifications on the go with GitHub Mobile for iOS or Android. > You are receiving this because you authored the thread.Message ID: @.> > — > Reply to this email directly, view it on GitHub, or unsubscribe. > Triage notifications on the go with GitHub Mobile for iOS or Android. > You are receiving this because you commented.Message ID: @.>

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/synth-inference/synthdid/issues/78#issuecomment-1006323895, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANV7XHYJSZ2GQ3BV6CYDA3UUU3ALANCNFSM5LJXLPTQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

cyfreya commented 2 years ago

Thanks a lot !!!

------------------ 原始邮件 ------------------ 发件人: "synth-inference/synthdid" @.>; 发送时间: 2022年1月6日(星期四) 下午3:08 @.>; @.**@.>; 主题: Re: [synth-inference/synthdid] Error in apply(Y[1:N0, 1:T0], 1, diff) : dim(X) must have a positive length (Issue #78)

Neither synthdid nor xsynthdid estimates weights that are based on covariates.

On Thu, Jan 6, 2022 at 1:45 AM cyfreya @.***> wrote:

> Thank you very much! I will appreciate it if you give some suggestions for > the question: There are two ways to add covariates: first is adding > covariates as an array when using the synthdid_estimate(), second is using > xsynthdid. I want to choose the unit and time weights based on covariates, > should i use the second way,&nbsp; and how many covariables can I > add?&nbsp;Can I compare the coefficient by the standard deviation and the > critical value of a normal distribution? > > > > Sincerely yours > > > > > > ------------------ 原始邮件 ------------------ > 发件人: "synth-inference/synthdid" @.&gt;; > 发送时间:&nbsp;2022年1月6日(星期四) 上午9:27 > @.&gt;; > @.**@.&gt;; > 主题:&nbsp;Re: [synth-inference/synthdid] Error in apply(Y[1:N0, 1:T0], 1, > diff) : dim(X) must have a positive length (Issue #78) > > > > > > I see. Our code doesn’t work if you have only one pre-treatment time step. > > The error you’re seeing is happening where it attempts to estimate the > noise level by looking at the first-differenced pre-treatment outcomes — > because there is only one pre-treatment time step, you can’t take first > differences. > > While we could tweak the code a bit to make it work in this case, > synthetic control methods aren’t really appropriate for settings with one > pre-treatment time step. With only one pre-treatment observation for each > unit, there’s not really enough information available to learn useful > synthetic control weights. > > Best, > Skip > On Jan 5, 2022, 8:16 PM -0500, cyfreya @.&gt;, wrote: > &gt; Thank you answer my question. In my study , n0 is 2178 (the number of > control units), t0 is 1(the number of pre-treatment time steps), dim Y = > 2248,3Sent from my Huawei phone-------- Original message --------From: > davidahirshberg @.&gt;Date: Wed, Jan 5, 2022, 20:22To: > synth-inference/synthdid @.&gt;Cc: cyfreya @.&gt;, Author > @.&gt;Subject: Re: [synth-inference/synthdid] Error in > apply(Y[1:N0, 1:T0], 1, diff) : dim(X) must have a positive length (Issue > #78) > &gt; What are N0, T0, and dim(Y)? > &gt; On Jan 5, 2022, 6:58 AM -0500, cyfreya @.&gt;, wrote: > &gt; &gt; when i used my data, there is an error "Error in apply(Y[1:N0, > 1:T0], 1, diff) : dim(X) must have a positive length',how to solve it, > thank you > &gt; &gt; — > &gt; &gt; Reply to this email directly, view it on GitHub, or unsubscribe. > &gt; &gt; Triage notifications on the go with GitHub Mobile for iOS or > Android. > &gt; &gt; You are receiving this because you are subscribed to this > thread.Message ID: @.&gt; > &gt; > &gt; > &gt; —Reply to this email directly, view it on GitHub, or > unsubscribe.Triage notifications on the go with GitHub Mobile for iOS or > Android. > &gt; You are receiving this because you authored the thread.Message ID: > @.&gt; > &gt; — > &gt; Reply to this email directly, view it on GitHub, or unsubscribe. > &gt; Triage notifications on the go with GitHub Mobile for iOS or Android. > &gt; You are receiving this because you commented.Message ID: > @.&gt; > > — > Reply to this email directly, view it on GitHub, or unsubscribe. > Triage notifications on the go with GitHub Mobile for iOS or Android. > You are receiving this because you authored the thread.Message ID: > @.&gt; > > — > Reply to this email directly, view it on GitHub > <https://github.com/synth-inference/synthdid/issues/78#issuecomment-1006323895&gt;, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AANV7XHYJSZ2GQ3BV6CYDA3UUU3ALANCNFSM5LJXLPTQ&gt; > . > Triage notifications on the go with GitHub Mobile for iOS > <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&amp;mt=8&amp;pt=524675&gt; > or Android > <https://play.google.com/store/apps/details?id=com.github.android&amp;referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub&gt;. > > You are receiving this because you commented.Message ID: > @.***> >

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you authored the thread.Message ID: @.***>

iProdigy commented 2 years ago

I am also running into this problem: Error in apply(Y, 2, function(col) { (main.R#69): dim(X) must have a positive length when calling vcov with either the jackknife or bootstrap method.

Y is a 34x5 matrix with values ranging from -3000 to -1500 (approx) N0 = 3 T0 = 3

The placebo method gives the following error: must have more controls than treated units to use the placebo se

Thanks in advance

 

Edit: Altering my set of controls (via xsynthdid), my Y matrix now contains both negative and positive values. Here, the jackknife method was able to produce a SE while bootstrap/placebo produced the same errors as above

Edit2: The signs may be a red herring; another set of controls produced a Y matrix with both negative and positive values and the jackknife method threw the error above

cyfreya commented 2 years ago

code doesn’t work if you have only one pre-treatment time step.The error you’re seeing is happening where it attempts to estimate the noise level by looking at the first-differenced pre-treatment outcomes — because there is only one pre-treatment time step, you can’t take first differences.Sent from my phone-------- Original message --------From: Sidd @.>Date: Sun, Apr 24, 2022, 11:01To: synth-inference/synthdid @.>Cc: cyfreya @.>, Author @.>Subject: Re: [synth-inference/synthdid] Error in apply(Y[1:N0, 1:T0], 1, diff) : dim(X) must have a positive length (Issue #78) I am also running into this problem: Error in apply(Y, 2, function(col) { (main.R#69): dim(X) must have a positive length when calling vcov with either the jackknife or bootstrap method. Y is a 34x5 matrix with values ranging from -3000 to -1500 (approx) N0 = 3 T0 = 3 The placebo method gives the following error: must have more controls than treated units to use the placebo se Thanks in advance

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

iProdigy commented 2 years ago

code doesn’t work if you have only one pre-treatment time step.

My understanding is that there are 3 pre-treatment periods (which is reflected in the T0 = 3) - am I missing something?

Edit: since my specific issue causing the error is different than yours, perhaps I should move this to its own github ticket

cyfreya commented 2 years ago

my problem is that there is only one pre period. it is not suitable for yours. sorrySent from my phone-------- Original message --------From: Sidd @.>Date: Sun, Apr 24, 2022, 12:35To: synth-inference/synthdid @.>Cc: cyfreya @.>, Author @.>Subject: Re: [synth-inference/synthdid] Error in apply(Y[1:N0, 1:T0], 1, diff) : dim(X) must have a positive length (Issue #78)

code doesn’t work if you have only one pre-treatment time step.

My understanding is that there are 3 pre-treatment periods (which is reflected in the T0 = 3) - am I missing something?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>