Coder Social home page Coder Social logo

lpirfs's People

Contributors

adaemmerp 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

Watchers

 avatar  avatar  avatar

lpirfs's Issues

Cumulative Impulse Responses

Hi,

are there any theoretical considerations regarding a possible implementation of cumulative Impulse Response Functions for the linear local projection method?

Lag length in lp_nl

Hello, excellent Package: My question is how do I switch off the lag length and use my fixed lag. ;

esults_nl <- lp_nl(endog_data,

  •               lags_endog_lin = 12,   # Number of lags for (reduced) linear VAR to obtain shock matrix. 
    
  •               lags_endog_nl  = 12,   # Number of lags for nonlinear model. 
    
  •                trend          = 0,    # 0 = no trend, 1 = trend, 2 = trend & trend^2.
    
  •               shock_type     = 0,  # 0 = standard deviation shock, 1 = unit shock.
    
  •                confint        = 1.67, # Width of confidence bands: 
    
  •                # 1 = 68%, 1.67 = 90%, 1.96 = 95%.
    
  •                hor            = 36,   # Length of irf horizons.
    
  •                switching      = endog_data$ACLR, # Use inflation rate as switching variable.
    
  •                use_hp         = TRUE, # Use HP-filter? TRUE or FALSE.   
    
  •                lambda         = 129,600, # Ravn and Uhlig (2002):
    
  •                # Anuual data    = 6.25
    
  •                # Quarterly data = 1600
    
  •                # Monthly data   = 129,600
    
  •                gamma          = 6,) 
    

Error in lp_nl(endog_data, lags_endog_lin = 12, lags_endog_nl = 12, trend = 0, :
Possible lag length criteria are AICc, AIC or BIC or NaN if lag length is specified.

Reason for cumul_mult only being in iv() functions

Hi Philipp,
Thanks for the very useful package. I wonder about the reason that the option cumul_mult was in the update only incorporated in lp_lin_iv() and lp_nl_iv() but not in the standard lp_lin() and lp_nl() functions, where the shock matrix is obtained via the Cholesky decomposition.
Thus, I am wondering whether it would be sufficient to update in lp_lin() the definition of yy as below or if it is not as straightforward and would need to be incorporated already in Cholesky decomposition:
yy <- y_lin[h:dim(y_lin)[1], ], for example, in row 353 of lp_lin() to
yy <- dplyr::lead(y_lin, (h - 1)) - dplyr::lag(y_lin, 1), starting from 438 in lp_lin_iv()
Thanks in advance.

Nonlinear impulse-response functions (s1 & s2)

I'd like to thank you for a great package with an intuitive interface.

Could you please provide more explanations about the difference between the impulse-response functions produced by lp_nl()? More specifically, what is the difference between irf_s1_* and irf_s2_*? The function documentation talks about their content; however, I was not able to find anything about what they actually are. Any pointer would be greatly appreciated.

Thank you.

Regression

Dr. Adämmer,

When using your package, with an identified shock, I have the following equation:
image
(lp_lin_iv())

Which one corresponds to the vector of control variables (without h-horizon)? Contemp_data or exog_data? what form do they individually take in the regression structure?

Thank you.

Do you please plan to add diagnostics to the lp_lin_panel and lp_nl_panel?

Hello,

thank you for this package! I am using it while working on my PhD on central banks policy. I do not have access to Stata at my institution so I try it in R.
I have found the coefficients in the "reg_summaries". However, I am wondering if there is a similar function as in lp_lin and lp_nl for diagnostics (I have found in the documentation "diagnostics_list") or if you please plan to add it.

Otherwise, I would be very grateful if you advise me on how I could get it.

Thank you in advance!

Jeanette

Horizons in cumulative panel LP

Hi!

First of all many thanks for the fantastic package.

I have a question about horizons which are being used for lp_lin_panel. In the reference manual (page 16) it is stated that the horizons range from 0 to H-1. However, plotting the LP using plot.lpirfs_lin_panel_obj, we obtain an impulse response that starts at 1 on the x-axis.

I wanted to double check whether the lp_lin_panel with cumul_mult = TRUE uses horizons from 0 to H-1 as stated in the reference manual or from 1 to H.

Using ip_lin_iv for impulse response function using 2SLS

Hi,
I was having trouble trying to run the following commands:

base_iv1 <- lp_lin_iv(
endog_data = endog,
shock = shock,
cumul_mult = TRUE,
instrum = instrum,
use_twosls = TRUE,
lags_endog_lin = 4,
exog_data = exog,
lags_exog = 4,
lags_criterion = NaN,
trend = 0,
confint = 1.96,
hor = 12
)

and I get an error "Error in { :
task 1 failed - "Mat::insert_cols(): given object has an incompatible number of rows"

Specifically, it seems that whenever I put both "cumul_mult = TRUE" and " use_twosls = TRUE", it would report such an error.
The number of rows in all data frames I put are the same.

IV in non-linear panel LP

If not mistaken, the current version does not allow to augment the non-linear panel LP with IV (at least there is no option to specify the instrument). Would it be a relatively straight-forward task to implement this (i.e., with already having the existing routines on non-linear LP and the IV setting for panel LP)?

Any guidance would be of help.

how to get coefficients of regressions for each horizon in lpirfs?

After running the model lp_lin_iv or lp_nl_iv, how do I recover the coefficients of the regression at each horizon? The regression summaries only displays the R-square, adjusted R-square, p-value and F-stat. Surprisingly, the coefficients are not displayed. How do I recover the coefficients. Appreciate your response. I have been trying to find answer to this question for a long time.

Option to include lagged forecast errors

Many thanks for your great package! As I did not find any information about this, I was wondering if there is an option to recursively include the forecast errors from horizon h−1 in the local projection at horizon h?
This refers to Jorda (2005, p. 166) to increase estimation efficiency: "In principle, the efficiency of these estimators can be improved upon by recursively including the residuals of the stage s-1 local projection as regressors in the stage s local projection."

`cumul_mult` option for `lp_lin()`

Hi,

Thanks for a very handy package!

Would it be possible to add the cumul_mult option for the single time series functions? As I understand, currently, it is only available for the panel data functions.

Regarding confidence intervals

Sir i really appreciate for the library lpirfds and it has been very useful I was facing the issue of how to obtain the confidence intervals. As in the source code given by you it is there , but then it isn not extracted in the putput.
So if suppose in analysis i want to use the confidence interval then what is the way for doing it.
Thanks & Regards

Mandar

Use of another model in calculating standard errors in lpirfs::lp_lin()

Hello, I appreciate the excellent alternative you've provided for the data-driven Impulse response.

Upon reviewing the code base of the lp_lin() function, I discovered that it relies on Ordinary Least Squares (OLS) for computing the impulse response. However, I'm curious if there's a possibility of employing a different model, such as Random Forest or GAM, to calculate standard errors and subsequently generate impulse responses.

I would greatly appreciate it if you could let me know if this is feasible, and if so, kindly share any helpful tips or insights for implementing this approach. Thank you.

question on historical decomposition

Thanks a lot @AdaemmerP for this very useful package.

I'm trying to implement historical decomposition using local projections.
From the traditional VAR structure it is easy to understand the process having as a starting point the Wold decomposition.
I was wondering if you have any idea how to calculate historical decomposition under the local projection framework.
Any ideas or reference papers would be welcome.
Thanks

Do you plan to add something similar to reg_summaries of lp_lin_panel in lp_lin

Hello,

First thanks a lot for the package. I am using it to work on my Phd on monetary and macroprudential policy in emerging markets, it allowed me to work on R rather than on Stata yet.

After searching in the package for the coefficients of the exogenous variables of the linear local projections, I have seen in another post that they are not provided in the function for individual regressions.
I was wondering if you planned to implement something similar to reg_summaries of lp_lin_panel into lp_lin in the future.

Otherwise, do you have any advice on how I could retrieve these coefficients manually, out of lpirf package ?

It would be great.

Many thanks by advance,

Anatole

Inquiry about lpirfs, horizons

Hi!

Thank you for creating such a useful package. It has been very helpful.

I just wanted to ask about the horizons of irfs that the package gives. Does h=1 mean the response of y_{t+1} to the shock_{t}?

If so, is there any way I could see the response of y_{t} to the shock_{t}? In other words, I want to know the response "on impact" (h=0).

Thank you so much.

Best,

Husang Kim

Lags of the endogenous variable in lp_lin_panel()

Hello,

Thanks for the package! I was curious if lags of the endogenous variable are supported when working with panel data and using the lp_lin_panel() function.

Though I guess a solution would be to create a lag of the endogenous variable and specify that as one of the exogenous variables?

Kind regards,
Eric

lp_lin.R

Hi Phillip.
Maybe I wrong, but I think that the next code isn't correct:

First value of horizon is merely the shock

  irf_lin_mean[, 1, i]   <- t(d[, i])
  irf_lin_low[,  1, i]   <- irf_lin_mean[, 1, i]
  irf_lin_up[,   1, i]   <- irf_lin_mean[, 1, i]

Why are you set up for the up and low confidence interval value equal mean?
You calculate the 1'st dot of IRF, but the error shouldn't be equal it, isn't it?

truncation parameter in newey_west

In Jorda (2005), the Newey-West Lag length is 1 + p + h, where h is length of the impulse response (h = 24 in Jorda (2005)), p is lag length in the VAR. The well-received textbook Introduction to Econometrics by Stock & Watson (2015) set the truncation parameter equal 0.75 T^(1/3).

In lp_lin function:
for (h in 1:(specs$hor)){
nw_results = lpirfs::newey_west(yy[, k], xx, h)
}

So, if h = 1, truncation parameter = 1
if h = 2, truncation parameter = 2
......
I think this does not match the existing literature. Usually, the truncation parameter is fixed and related to the length of the sample.

Information Criterion issues

Hi,
When using lags_criterion='AIC', I met an issue in my output with the function summary(results_lin)[[1]][4] and summary(results_lin). This problem does not arise when using a defined number of lags. There is no issues with the plot.
Thanks in advance for your response
summary(results_lin)[[1]][4]

[[1]]

NULL

summary(results_lin)

$Shock: c.cons.

$Shock: c.cons.[[1]]

$Shock: c.cons.[[1]]$h 1

R-sqrd. Adj. R-sqrd. F-stat p-value

c.cons. 0.9994698 0.9994478 45454.01 0

c.output. 0.9991177 0.9990897 35590.77 0

attr(,"names")

[1] "c.cons." "c.output." NA NA NA NA

[7] NA NA

Robust covariance estimators in 'lp_lin_panel' and 'lp_nl_panel'

The development version of lpirfs contained two bugs regarding the robust covariance matrix estimators:

  • 'lp_lin_panel' always used 'vcovSCC' (Driscoll-Kraay estimator) if a robust covariance estimator has been specified.
  • 'lp_nl_panel' always used 'vcovNW' (Newey-West estimator) if a robust covariance estimator has been specified.

Hypothesis testing and coefficient interpretation

Thank you for a convenient package. Two points:

  1. How do we go about running t-tests on whether the two shocks (negative and positive) are statistically significantly different (i.e. coefficients on s1 shock and s2 shock are statistically significantly different at each horizon). We are testing for sign asymmetry in monetary policy shocks. We have tried using built-in packages in R for hypothesis testing, but because the results are stored unlike those for a typical regression (eg. we have no access to the variance-covariance matrix), we are not sure how to run the t-tests. Do you have sample code that could be used?
  2. Are the results on the negative shocks (s1) flipped already? i.e. should we interpret the results as a one unit decrease (from say -1 to -2) has the s1 coefficient effect on the dependent variable, or are the results not flipped so the interpretation would follow those for a typical OLS (i.e. a one unit increase, from -2 to -1) has the s1 coefficient effect (in which case we have to flip the sign ourselves). Thanks!

Cumul_mult question

Hello,

I have a quick question regarding the cumul_mult argument. I have reviewed the documentation and if TRUE, I understand that it is estimated via y(t+h) − y(t−1).

I have been running a model, which gives me very different IRFs (one >0 and one<0, for the whole horizon) when cumul_mult TRUE/FALSE. Is that possible?

Thank you very much. Kind regards, Jeanette

How to derive NW standard errors for impulse responses?

Hi,

Could you please give an example of how can I extract the standard errors for the impulse responses that I calculate in lp_lin_iv function? I am new in R and I am using this package for my thesis.

Thank you for creating this package it's very helpful.

Logit specification

Hello,

thank you for the package and every improvement. I am working with binary dependent variables and estimating the linear probability panel model using local projections lp_lin_panel and lp_nl_panel functions. I am wondering whether it is possible to switch to a logit model in your package (sth like in Schularick et al (2020): Leaning against the wind and crisis risk, p33).

Thank you very much. Kind regards,

Jeanette

cumul_mult question

Hello, thanks for the package and the resources, its been very helpful for my undergraduate thesis. I have some questions regarding the cumul_mult option.

Given that I'm trying to modify lp_nl so I can get cumulative respones (similar to lp_nl_iv) I noticed that the IRF change very little (if nothing at all). Is this supposed to happen?

Thank you

Bug in hp_filter

There is a bug in the hp_filter function. The value "lambda" refers to the cut-off frequency of the Hodrick-Prescott filter. To obtain values for lambda = (6, 1600, 129600), you have to type in (1, 4, 12), respectively.

How to color

Dear Dr. Adämmer,
I used the function lp_lin_iv() to estimate the response of GDP and CO2 emission to external shocks. I plot the result using plot_lin(results_lin_iv).
1)I tried to change the colour but this function does not change the colour while I added the colour argument.
2) I also want to merge the plots.
Is there any solution to manipulate the plots in the normal way in R?
Thanks in advance.

Shock size in lp_lin_iv

Hello,

First of all, let me acknowledge the quality of the package - it is great and exactly just what I was looking for!

However, I have not found much information about the shock size in the function lp_lin_iv. I suppose it's a unit shock. Is there any possibility to modify these values? An example could be evaluating variable responses to the monetary policy shock (e.g., 25 basis points increase in a given interest rate).

Thank you for your clarification.

"lp_lin_panel" error message

Hi Philipp!

I am trying to run the lp_lin_panel function but am getting an awkward error message. When I run my code, that is:

library(foreign)
package_vector <- c("foreign", "readxl", "lpirfs", "httr", "dplyr", "plm", "data.table", "stargazer")
lapply(package_vector, require, character.only=TRUE)

rm(list=ls())


setwd("~/desktop")
data=read_excel("~/desktop/paneldata1Wdropped.xlsx")

data <- data %>%
dplyr::select(Maturity, Month, Issuances, Shock, exo1, exo2, exo3, exo4, exo5)

data_sample  = seq(1999-01-01, 2019-12-01)

local_proj <- lp_lin_panel(data_set  = data,  data_sample  = data_sample,
                              endog_data        = "Issuances", cumul_mult = TRUE,
                              shock             = "Shock",    diff_shock  = FALSE,
                              panel_model       = "random",  panel_effect = "individual",
                              robust_cov        = "vcovSCC", c_exog_data  = "exo1",
                              c_fd_exog_data    = NULL,
                              l_fd_exog_data    = NULL,
                              lags_fd_exog_data = 2,      confint      = 1.67,
                              hor               = 5)

plot_local_proj <- plot_lin(local_proj)
plot(plot_local_proj[[1]])

I get:

Error in plm.fit(data, model, effect, random.method, random.models, random.dfcor,  : 
  0 (non-NA) cases

Some answers on forums said it might be related to some NA values in my dataset, which I checked for and couldn't find, or it could be due to the random.method used ("swarm" rather than "amemiya").

I have asked for help around but no one could figure it out. I'm a pretty new user so maybe it's trivial, but I'd love to have your insight on the issue. You'll also find my data attached below. Thanks a lot for your time! Hoping it doesn't bother you too much.

Cheers,
Alex.

paneldata1Wdropped.xlsx

lp_nl

Hello, does regime 1 which gives values close to 0, always constitute the high regime of the switching variable and regime 2 which gives values close to 1 constitute the low regime of the switching variable? Thank you.

Standard error shock

Dear Professor Adaemmer,

I would like to know how to define a standard error shock with the command lp_lin_iv. I would like to define a standard error shock of the exogenous shock on one endogenous variable but the command is not for lp_lin_iv and I don't see how to do so. (By the way what is the default with lp_lin_iv ? )

With the command lp_lin it is shock_type=0. That said, I have a exogenous shock.

Thanks in advance for your response.

R crashes on running example

Hi,
Thanks for putting this code together and making it available.
I'm running R 4.2.2 on Linux Ubuntu 22.04 (kernel 15.0.52-generic). I downloaded your package from github.
I ran your example (after changing rgdp.. for rgdpmad (as the original is not in the dataset any longer) and R crashed.
Any clue what might be going wrong?
Thanks
Gianni

`jst_data<-readstata13::read.dta13(file = '../DATA/JSTdatasetR6.dta')
jst_data <- jst_data %>%
dplyr::filter(year <= 2013) %>%
dplyr::select(country, year, everything())
data_set <- jst_data %>%
mutate(stir = stir) %>%
mutate(mortgdp = 100*(tmort/gdp)) %>%
mutate(hpreal = hpnom/cpi) %>%
group_by(country) %>%
mutate(hpreal = hpreal/hpreal[year==1990][1]) %>%
mutate(lhpreal = log(hpreal)) %>%

              mutate(lhpy     = lhpreal - log(rgdpmad))        %>%
            mutate(lhpy     = lhpy - lhpy[year == 1990][1]) %>%
            mutate(lhpreal  = 100*lhpreal)                  %>%
            mutate(lhpy     = 100*lhpy)                     %>%
            ungroup()                                       %>%

            mutate(lrgdp    = 100*log(rgdpmad))              %>%
            mutate(lcpi     = 100*log(cpi)) 		            %>%
            mutate(lriy     = 100*log(iy*rgdpmad))           %>%
            mutate(cay      = 100*(ca/gdp))                 %>%
            mutate(tnmort   = tloans - tmort)               %>%
            mutate(nmortgdp = 100*(tnmort/gdp))             %>%
            dplyr::select(country, year, mortgdp, stir, ltrate,
                          lhpy, lrgdp, lcpi, lriy, cay, nmortgdp)

data_sample <- seq(1870, 2013)[!(seq(1870, 2016) %in%
c(seq(1914, 1918), seq(1939, 1947)))]
results_panel <- lpirfs::lp_lin_panel(data_set = data_set,
data_sample = data_sample,
endog_data = "mortgdp",
cumul_mult = TRUE,

                            shock             = "stir",
                            diff_shock        = TRUE,
                            panel_model       = "within",
                            panel_effect      = "individual",
                            robust_cov        = "vcovSCC",

                            c_exog_data       = "cay",
                            l_exog_data       = "cay",
                            lags_exog_data    = 2,
                            c_fd_exog_data    = colnames(data_set)[c(seq(4,9),11)],
                            l_fd_exog_data    = colnames(data_set)[c(seq(3,9),11)],
                            lags_fd_exog_data = 2,

                            confint           = 1.67,
                            hor               = 5)`

Automatic lag selection

Hi, seems that the automatic lag selection does not work. The example code with your example data:

g_data <- ag_data
sample_start <- 7
sample_end <- dim(ag_data)[1]

Endogenous data

endog_data <- ag_data[sample_start:sample_end,3:5]
shock <- ag_data[sample_start:sample_end, 3]

Estimate linear model

results_lin_iv <- lp_lin_iv(endog_data,
max_lags = 12,
lags_criterion="AIC",
shock = shock,
trend = 0,
confint = 1.96,
hor = 20)

Gives the error
Error in if (is.nan(lags_endog_lin) & !is.character(lags_criterion)) { :
argument is of length zero

Can you point me to a solution?
Regards,
Martin

bug in function `create_lin_data.R`?

Have you encountered the following error: while running the 81st line
yx_all <- cbind(y_lin, x_lin) %>% stats::na.omit()

it gives the yx_all data.frame with inconsistent length with x_lin, then, when the program proceeds to line 101 (suppose I choose to use 2SLS), it will report an error saying "Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: X, Y", where X is the length of my instrument data, which is of the same length as y_lin and x_lin before running the 81st line; Y is the length of yx_all. I think the problem lies in the fact that we drop NAs in the 81st line. How should we fix this?

(I attach my data and my code of using the lp_lin_iv function here)
example.zip

Graph and horizons

Hello Dr. Adämmer,

First of all, thanks for your package, it's been really useful.

I have three questions regarding the graphs and results (I'm using lp_lin_iv() if it helps):

I've noticed that all the graphs start with horizon=1, I assume this is the first impact of the shock on the endogenous variable. But I wonder because the equation in page 4 (in your PDF) starts from h=0, which I assume that's the first response but when I observe the graph it starts from h=1. May you explain me this?

Second question is about the color, how can I get different colors for a graph if it is possible? Or at least get a different color line for the mean.

Third question, is it possible to round the values obtained from the tables?

Thank you.

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.