Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnSchorfheide #167

Open
breussf opened this issue Jan 16, 2022 · 16 comments
Open

AnSchorfheide #167

breussf opened this issue Jan 16, 2022 · 16 comments

Comments

@breussf
Copy link

breussf commented Jan 16, 2022

When running the Julia file "an_schorfheide.jl" one gets immediately an error message "Load Error: UndefVarError: AbstractRepModel not defined". This happens in Julia version 1.1.1 and also in version 1.7.1.
How can one run the an_schorfheide file without this error message?
Best regards,
Fritz

@ShlokG
Copy link
Member

ShlokG commented Jan 19, 2022

Hi Fritz,

The reason you get this error is that the AbstractRepModel type is defined in src/abstractdsgemodel.jl so you would need to include that file before including "an_schorfheide.jl". However, the package is meant to be used is by doing loading the package and then using the functions built into it rather than by including individual files. If you look at src/DSGE.jl, you will see that loading the package will automatically include the "an_schorfheide.jl" file with the pre-requisite files loaded earlier. So, after loading the package, you can use any of the functions defined in "an_schorfheide.jl" to create your own AnSchorfheide model object. The following code, for example, will create an AnSchorfheide model object:

using DSGE
m = DSGE.AnSchorfheide()

Regards,
Shlok

@breussf
Copy link
Author

breussf commented Jan 19, 2022

Dear Shlok - thanks!
I used your advice an got again an error message, after proceeding as follows:

julia> using DSGE
julia> m = DSGE.AnSchorfheide()
Dynamic Stochastic General Equilibrium Model
no. states: 8
no. anticipated policy shocks: 0
data vintage: 220119
description:
Julia implementation of model defined in 'Bayesian Estimation of DSGE Models' by Sungbae An and Frank Schorfheide: AnSchorfheide, ss0
julia> include("d:/FRBNY-DSGE_in_Julia/DSGE.jl/src/abstractdsgemodel.jl")
ERROR: LoadError: UndefVarError: ModelConstructors not defined
Stacktrace:
[1] top-level scope
@ d:\FRBNY-DSGE_in_Julia\DSGE.jl\src\abstractdsgemodel.jl:1
in expression starting at d:\FRBNY-DSGE_in_Julia\DSGE.jl\src\abstractdsgemodel.jl:1

There must be another missing input - but which one?
Fritz

@breussf
Copy link
Author

breussf commented Jan 19, 2022 via email

@ShlokG
Copy link
Member

ShlokG commented Jan 19, 2022

Hi Fritz,

Sorry I wasn't clear. Once you do "using DSGE" all the functions within "an_schorfheide.jl" are available to you so you don't need to include any files. "m" is an An-Schorfheide model object as the Julia message indicates which I imagine is what you want.

If you are interested, the reason for the error is that you need to do "using ModelConstructors" before. However, going down this road is a slippery slope as there will undoubtedly be other files you would need to include before being able to include "an_schorfheide.jl". As a result, I recommend just doing loading DSGE.jl. However, if you want to do includes, you can just do "include src/DSGE.jl" and everything should work then.

One thing that might help is looking at the example scripts. For example, in the below script, we instantiate a Model1002 object: https://github.com/FRBNY-DSGE/DSGE.jl/blob/main/examples/run_default.jl

Regards,
Shlok

@breussf
Copy link
Author

breussf commented Jan 19, 2022 via email

@ShlokG
Copy link
Member

ShlokG commented Jan 19, 2022

Hi Fritz,

The package is not intended to be used by including individual files. Once you do using DSGE, all functions in an_schorfheide.jl and smets_wouters.jl are automatically loaded (which is the only purpose of loading in the files I can think of). Hence, you don't need to do include an_schorfheide.jl. Instead, you can just proceed to whatever code you intend to run after including the files. So, you just need to run using DSGE to load the files.

You can also check out https://github.com/FRBNY-DSGE/DSGE.jl/blob/main/examples/run_default.jl and just replace m = Model1002("ss10") with m = AnSchorfheide() or m = SmetsWouters() depending on the model you want.

Regards,
Shlok

@breussf
Copy link
Author

breussf commented Jan 20, 2022 via email

@ShlokG
Copy link
Member

ShlokG commented Jan 21, 2022

Hi Fritz,

I can't see the error message. I just see the following: "@.***"

If you are getting an issue in load_data(m; check_empty_columns = false) (line 51 of make_packet.jl), then the reason probably is that you need a FRED API key as we pull data from FRED. You can get an API key by making an account with FRED: https://fred.stlouisfed.org/docs/api/api_key.html.

If the issue is instead in usual_model_forecast (line 85 of make_packet.jl), then I would to see the error message you are getting to be able to debug it. The one issue I can imagine is that the input parameter file is not found. To resolve that problem, make sure you are running the file from DSGE.jl/examples. That is, you are running just include("make_packet.jl") as opposed to include("examples/make_packet.jl") or something similar. This is because the filepath for the input file relies on the current working directory being examples/.

Regards,
Shlok

@breussf
Copy link
Author

breussf commented Jan 21, 2022 via email

@ShlokG
Copy link
Member

ShlokG commented Jan 21, 2022

Hi Fritz,

To tell Julia your API key, I would recommend running the following:

ENV["FRED_API_KEY"] = "[Your API Key Here]"
include("make_packet.jl")

The first line defines the environment variable FRED_API_KEY in Julia which the function Fred() will automatically look for. The reason your code didn't work is that f is not passed into the function make_packet and so the Fred object you created is not used by the function.

Regards,
Shlok

@breussf
Copy link
Author

breussf commented Jan 21, 2022 via email

@ShlokG
Copy link
Member

ShlokG commented Jan 21, 2022

Hi Fritz,

The fact that it started forecasting and got through 8 blocks suggests that the FRED data is being loaded correctly. I still can't see the error message you are getting. I just see the following:

@.***
and:
@.***

I guess you are trying to copy and paste the error but GitHub is not picking it up. Could you save the error as an image and send that? I might be able to view that to help with debugging the issue.

Regards,
Shlok

@breussf
Copy link
Author

breussf commented Jan 22, 2022 via email

@breussf
Copy link
Author

breussf commented Jan 24, 2022 via email

@ShlokG
Copy link
Member

ShlokG commented Jan 25, 2022

Hi Fritz,

The warnings can be safely ignored. The error has to do with the inputted vector of parameter values not aligning with the model's internal parameters. Namely, overrides[:full] in line 55 is set to the file containing the parameter values but these values were constructed for Model1002("ss10") (as that's the model the example is for) whose parameters differ from the Smets-Wouters model.

Once you run run_default.jl, it estimates the model and stores the results in the directory given by rawpath(m, "estimate"). Using default settings, this will be in DSGE/save/output_data/smets_wouters/ss0/estimate/raw/mhsave_vint=181115.h5. In line 55 of make_packet.jl, you want to replace the filepath and point to this filepath instead.

Regards,
Shlok

@ShlokG ShlokG mentioned this issue Jan 25, 2022
@breussf
Copy link
Author

breussf commented Jan 26, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants