| Title: | Solves a Generic Stochastic Growth Model with a Representative Agent |
|---|---|
| Description: | It computes the solutions to a generic stochastic growth model for a given set of user supplied parameters. It includes the solutions to the model, plots of the solution, a summary of the features of the model, a function that covers different types of consumption preferences, and a function that computes the moments of a Markov process. Merton, Robert C (1971) <doi:10.1016/0022-0531(71)90038-X>, Tauchen, George (1986) <doi:10.1016/0165-1765(86)90168-0>, Wickham, Hadley (2009, ISBN:978-0-387-98140-6 ). |
| Authors: | Thomas Vigie <[email protected]> |
| Maintainer: | Thomas Vigie <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.1 |
| Built: | 2026-05-18 06:56:41 UTC |
| Source: | https://github.com/thomasvigie/sgmodel-v-0.1.1 |
The function Markovmoments computes the expectation, variance, autocovariance and autocorrelation of a Markov process.
Markovmoments(states, ptm, ...)Markovmoments(states, ptm, ...)
states |
A numerical vector with the states of the Markov process. |
ptm |
The probability transition matrix, a square matrix of dimension length(states) whose columns sum to one. |
... |
Additional arguments. |
It returns a list containing:
Expectation |
The mean of the process. |
Variance |
The variance of the process. |
Autocovariance |
The autocovariance of the process. |
Autocorrelation |
The autocorrelation of the process. |
Stationary distribution |
The stationary distribution of the process, used for the computation of the moments. |
a <- c(-1, 1) A <- matrix(c(0.5, 0.6, 0.5, 0.4), 2, 2) Markovmoments(a, A)a <- c(-1, 1) A <- matrix(c(0.5, 0.6, 0.5, 0.4), 2, 2) Markovmoments(a, A)
The sgmodel package provides three important functions:
sgmod, util and Markovmoments.
sgmodel functionThe sgmodel function solves a standard stochastic growth model using value function iteration. The stochastic component follows an autoregressive process of order one, and is discretized by a finite state Markov process.
util functionIt computes values for various uility functions encountered in economic theory.
Markovmoments functionIt computes the four moments of a finite state Markov chain: expectation, variance, autocovariance and autocorrelation.
The function plot_sgmod returns a plot of the Savings value of a sgmodel object on the Capital grid value.
plot_sgmod(x, ...)plot_sgmod(x, ...)
x |
A |
... |
Additional arguments. |
It returns a plot using ggplot that graphs the Savings decisions from the sgmodel object on the Capital grid. The plot shows as many facets as length(Z) where Z is the vector of states of the TFP process.
Wickham H (2009), ggplot2: Elegant Graphics for Data Analysis. URL http://ggplot2.org
model <- sgmodel( grid = 100, rho = 0.2, sigma = 0.02) plot_sgmod(model) grid <- 200 utiltype <- "CRRA" utilparam <- 4 A <- 1 depre <- 0.03 discount <- 0.95 prod <- 0.3 states <- 5 m <- 2 rho <- 0.2 sigma <- 0.02 model <- sgmodel(grid, utiltype, utilparam, A, depre, discount, prod, states, m, rho, sigma) plot_sgmod(model)model <- sgmodel( grid = 100, rho = 0.2, sigma = 0.02) plot_sgmod(model) grid <- 200 utiltype <- "CRRA" utilparam <- 4 A <- 1 depre <- 0.03 discount <- 0.95 prod <- 0.3 states <- 5 m <- 2 rho <- 0.2 sigma <- 0.02 model <- sgmodel(grid, utiltype, utilparam, A, depre, discount, prod, states, m, rho, sigma) plot_sgmod(model)
The function print_sgmod prints results of the sgmodel function.
print_sgmod(x, ...)print_sgmod(x, ...)
x |
A |
... |
Additional arguments. |
The function prints the call of the function, the Savings, Consumption and Capital grid vectors from sgmodel.
grid <- 200 utiltype <- "CRRA" utilparam <- 4 A <- 1 depre <- 0.03 discount <- 0.95 prod <- 0.3 states <- 3 m <- 5 rho <- 0.2 sigma <- 0.02 model <- sgmodel(grid, utiltype, utilparam, A, depre, discount, prod, states, m, rho, sigma) print_sgmod(model)grid <- 200 utiltype <- "CRRA" utilparam <- 4 A <- 1 depre <- 0.03 discount <- 0.95 prod <- 0.3 states <- 3 m <- 5 rho <- 0.2 sigma <- 0.02 model <- sgmodel(grid, utiltype, utilparam, A, depre, discount, prod, states, m, rho, sigma) print_sgmod(model)
The function print.summary_sgmod prints a summary for a sgmodel object.
## S3 method for class 'summary_sgmod' print(x, ...)## S3 method for class 'summary_sgmod' print(x, ...)
x |
An object of class |
... |
Additional arguments. |
It returns a list with the model parameters. It includes:
Utility function |
The type of utility function. See the details of |
Capital share |
The exponent on capital in the Cobb-Douglas production function. |
Discount factor |
The discount factor used in the model. |
Depreciation |
The depreciation rate of capital used in the model. |
Rho |
Autocorrelation of the TFP AR(1) process. |
Sigma |
Standard deviation of the white noise in the TFP process. |
Number of TFP states |
Number of states of the TFP process. |
grid <- 200 utiltype <- "CRRA" utilparam <- 4 A <- 1 depre <- 0.03 discount <- 0.95 prod <- 0.3 states <- 3 m <- 4 rho <- 0.2 sigma <- 0.02 model <- sgmodel(grid, utiltype, utilparam, A, depre, discount, prod, states, m, rho, sigma) summary_sgmod(model)grid <- 200 utiltype <- "CRRA" utilparam <- 4 A <- 1 depre <- 0.03 discount <- 0.95 prod <- 0.3 states <- 3 m <- 4 rho <- 0.2 sigma <- 0.02 model <- sgmodel(grid, utiltype, utilparam, A, depre, discount, prod, states, m, rho, sigma) summary_sgmod(model)
The function sgmodel computes the solutions to a generic stochastic growth model after discretizing the distribution of the stochastic element.
sgmodel(grid, utiltype, utilparam, A, depre, discount, prod, states, m, rho, sigma, ...)sgmodel(grid, utiltype, utilparam, A, depre, discount, prod, states, m, rho, sigma, ...)
grid |
A numerical value, the number of capital grid points to consider for k (t). Default value set to 1000. |
utiltype |
The type of preference for the |
utilparam |
Numerical value, preference parameter for the |
A |
Numerical value, preference parameter for the |
depre |
Numerical value for the depreciation parameter. Must be between 0 and 1. Default value set to 1. |
discount |
Numerical value for the discount factor. Must be (strictly) between 0 and 1. Default value set to 0.95. |
prod |
Numerical value for the Cobb-Douglas production function. Must be (strictly) between 0 and 1. Default value set to 0.3. |
states |
umerical value for the number of states of the Markov process approximating the TFP process. Default value set to 2. |
m |
Numerical value for the |
rho |
Autocorrelation of the TFP AR(1) process, used to approximate the process with a Markov process. |
sigma |
Standard deviation of the white noise in the TFP process, used to approximate the process with a Markov process. |
... |
Additional arguments. |
The function returns a list containing:
Capital grid |
Vector of values for capital. |
Savings |
Vector of size ( |
Consumption |
Vector of size ( |
Z |
States of the TFP process. |
PTM |
The probability transition matrix of the process. |
Production parameter |
The exponent on capital in the Cobb-Douglas production function. |
Utility type |
The type of utility function. See the details of "util" for the available types |
Discount factor |
The discount factor used in the model. |
Depreciation |
The depreciation rate of capital used in the model. |
Rho |
Autocorrelation of the TFP AR(1) process. |
Sigma |
Standard deviation of the white noise in the TFP process. |
Tauchen G (1986), Finite state markov-chain approximations to univariate and vector autoregressions. Economics letters, 20(2), 177–181.
Merton R. C (1971), Optimum consumption and portfolio rules in a continuous-time model. Journal of Economic Theory, 3(4), 373–413. URL http://www.sciencedirect.com/science/article/pii/002205317190038X
model <- sgmodel(grid= 100, rho = 0.2, sigma = 0.02) grid <- 200 utiltype <- "CRRA" utilparam <- 4 A <- 1 depre <- 0.03 discount <- 0.95 prod <- 0.3 states <- 5 m <- 10 rho <- 0.2 sigma <- 0.02 model <- sgmodel(grid, utiltype, utilparam, A, depre, discount, prod, states, m, rho, sigma)model <- sgmodel(grid= 100, rho = 0.2, sigma = 0.02) grid <- 200 utiltype <- "CRRA" utilparam <- 4 A <- 1 depre <- 0.03 discount <- 0.95 prod <- 0.3 states <- 5 m <- 10 rho <- 0.2 sigma <- 0.02 model <- sgmodel(grid, utiltype, utilparam, A, depre, discount, prod, states, m, rho, sigma)
The function summary_sgmod prints a summary for results of the sgmodel function.
summary_sgmod(object, ...)summary_sgmod(object, ...)
object |
A |
... |
Additional arguments. |
It returns a list with the model parameters. It includes:
Utility function |
The type of utility function. See the details of |
Capital share |
The exponent on capital in the Cobb-Douglas production function. |
Discount factor |
The discount factor used in the model. |
Depreciation |
The depreciation rate of capital used in the model. |
Rho |
Autocorrelation of the TFP AR(1) process. |
Sigma |
Standard deviation of the white noise in the TFP process. |
Number of TFP states |
Number of states of the TFP process. |
grid <- 200 utiltype <- "CRRA" utilparam <- 4 A <- 1 depre <- 0.03 discount <- 0.95 prod <- 0.3 states <- 3 m <- 3 rho <- 0.2 sigma <- 0.02 model <- sgmodel(grid, utiltype, utilparam, A, depre, discount, prod, states, m, rho, sigma) summary_sgmod(model)grid <- 200 utiltype <- "CRRA" utilparam <- 4 A <- 1 depre <- 0.03 discount <- 0.95 prod <- 0.3 states <- 3 m <- 3 rho <- 0.2 sigma <- 0.02 model <- sgmodel(grid, utiltype, utilparam, A, depre, discount, prod, states, m, rho, sigma) summary_sgmod(model)
The function util computes values for different types of utility functions and different parameters. See sgmodel_vignette for detailed functional forms.
util(x, A, prefparam, type = c("log", "CRRA", "CARA", "Cobb-Douglas", "CES"), ngoods, ...)util(x, A, prefparam, type = c("log", "CRRA", "CARA", "Cobb-Douglas", "CES"), ngoods, ...)
x |
A numeric vector of length ngoods with values to compute utility for. |
A |
A numerical value that will premultiply the utility function. Default value set to 1. |
prefparam |
A numerical value, the preference parameter applied to the utility function depending on type. |
type |
A character for the Type of utility function. Can be "log", "CRRA", "CARA", "Cobb-Douglas", "CES". Default type set to "log". |
ngoods |
Numerical value for the number of goods to consider. Default value set to 1. |
... |
Additional arguments. |
A numerical value, the utility function evaluated at the arguments.
Merton R. C (1971), Optimum consumption and portfolio rules in a continuous-time model. Journal of Economic Theory, 3(4), 373–413. URL http://www.sciencedirect.com/science/article/pii/002205317190038X.
x <- c(exp(1), exp(1)) A <- 2 type <- "log" ngoods <- 2 util(x = x, A = A, type = type, ngoods = ngoods)x <- c(exp(1), exp(1)) A <- 2 type <- "log" ngoods <- 2 util(x = x, A = A, type = type, ngoods = ngoods)