  ### 4.4 Random-coeﬃcients linear model

Mathematical representation

 ${y}_{it}={\mathbf{z}}_{it}^{\prime }{\gamma }_{i}+{\mathbf{x}}_{it}^{\prime }\beta +{𝜀}_{it},\phantom{\rule{2em}{0ex}}\phantom{\rule{1em}{0ex}}{𝜀}_{it}\sim \mathrm{N}\left(0,\frac{1}{\tau }\right),\phantom{\rule{1em}{0ex}}{\gamma }_{i}\sim \mathrm{N}\left(\stackrel{̄}{\gamma },{\Omega }^{-1}\right)$ (4.5)
• the model is estimated using observations from $N$ groups, each group observed for ${T}_{i}$ periods (balanced or unbalanced panels); the total number of observations is ${\sum }_{i=1}^{N}{T}_{i}$ and ${T}_{i}$ could be equal to one for all $i$ (cross-sectional data)
• ${y}_{it}$ is the value of the dependent variable for group $i$, observed in period $t$
• ${\mathbf{z}}_{it}$ is a $K\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}1$ vector that stores the values of the $K$ independent variables which are associated with group-speciﬁc coeﬃcients, for group $i$, observed in period $t$
• ${\mathbf{x}}_{it}$ is an $L\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}1$ vector that stores the values of the $L$ independent variables which are associated with coeﬃcients common to all groups, for group $i$, observed in period $t$ ($L$ could be zero)
• ${\gamma }_{i}$ is a $K\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}1$ vector of parameters associated with group $i$
• $\stackrel{̄}{\gamma }$ is a $K\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}1$ vector of parameters that represents the mean of the ${\gamma }_{i}$s
• $\Omega$ is a $K\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}K$ precision matrix for the distribution of the ${\gamma }_{i}$s
• $\beta$ is an $L\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}1$ vector of parameters
• $\tau$ is the precision of the error term: ${\sigma }_{𝜀}^{2}=\frac{1}{\tau }$

Priors

 Parameter Probability density function Default hyperparameters $\stackrel{̄}{\gamma }$ $p\left(\stackrel{̄}{\gamma }\right)=\frac{|{\mathbf{P}}_{\gamma }{|}^{1∕2}}{{\left(2\pi \right)}^{K∕2}}exp\left\{-\frac{1}{2}{\left(\stackrel{̄}{\gamma }-{\mathbf{m}}_{\gamma }\right)}^{\prime }{\mathbf{P}}_{\gamma }\left(\stackrel{̄}{\gamma }-{\mathbf{m}}_{\gamma }\right)\right\}$ ${\mathbf{m}}_{\gamma }={\mathbf{0}}_{K}$, ${\mathbf{P}}_{\gamma }=0.001\cdot {\mathbf{I}}_{K}$ $\Omega$ $p\left(\Omega \right)=\frac{|\Omega {|}^{\frac{n-K-1}{2}}|{\mathbf{V}}^{-1}{|}^{n∕2}}{{2}^{nK∕2}{\Gamma }_{K}\left(\frac{n}{2}\right)}exp\left\{-\frac{1}{2}tr\left({\mathbf{V}}^{-1}\Omega \right)\right\}$ $n={K}^{2}$, $\mathbf{V}=\frac{100}{K}\cdot {\mathbf{I}}_{K}$ $\beta$ $p\left(\beta \right)=\frac{|{\mathbf{P}}_{\beta }{|}^{1∕2}}{{\left(2\pi \right)}^{L∕2}}exp\left\{-\frac{1}{2}{\left(\beta -{\mathbf{m}}_{\beta }\right)}^{\prime }{\mathbf{P}}_{\beta }\left(\beta -{\mathbf{m}}_{\beta }\right)\right\}$ ${\mathbf{m}}_{\beta }={\mathbf{0}}_{L}$, ${\mathbf{P}}_{\beta }=0.001\cdot {\mathbf{I}}_{L}$ $\tau$ $p\left(\tau \right)=\frac{{b}_{\tau }^{{a}_{\tau }}}{\Gamma \left({a}_{\tau }\right)}{\tau }^{{a}_{\tau }-1}{e}^{-\tau {b}_{\tau }}$ ${a}_{\tau }=0.001$, ${b}_{\tau }=0.001$

Syntax

$\left[$<model name> = $\right]$ lm_rc( y ~ z1 z2  zK $\left[$$|$ x1 x2 $\dots$ xL$\right]$ $\left[$, <options> $\right]$ );

where:

• y is the dependent variable name, as it appears in the dataset used for estimation
• z1 z2 $\dots$zK is a list of the names, as they appear in the dataset used for estimation, of the independent variables which are associated with group-speciﬁc coeﬃcients; when a constant term is to be included in the set of group-speciﬁc coeﬃcients this must be requested explicitly
• x1 x2 $\dots$xL is is a list of the names, as they appear in the dataset used for estimation, of the independent variables which are associated with coeﬃcients common to all groups; when a constant term is to be included in the set of common coeﬃcients, this must be requested explicitly An independent variable could be included in either the x or the z variable list, depending on whether the parameter associated with this variable is common to all groups or not. However, including a variable in both lists would lead to exact multicollinearity and, in this case, BayES will issue an error. Before using the lm_rc() function the dataset used for estimation must be declared as a panel dataset using the set_pd() function (see section B.13). In the case of cross-sectional data, the dataset still needs to be declared as a panel, but the group-id variable could be constructed as a list of unique integers using, for example, the range() function. For groups observed only once, a group-speciﬁc parameter associated with a constant term cannot be distinguished from the error term (${𝜀}_{it}$). Thus, a warning is produced when a constant term is included in the z list and the dataset contains at least one group which is observed only once.

The optional arguments for the random-coeﬃcients linear model are:4

 Gibbs parameters "chains" number of chains to run in parallel (positive integer); the default value is 1 "burnin" number of burn-in draws per chain (positive integer); the default value is 10000 "draws" number of retained draws per chain (positive integer); the default value is 20000 "thin" value of the thinning parameter (positive integer); the default value is 1 "seed" value of the seed for the random-number generator (positive integer); the default value is 42 Hyperparameters "m_gamma" mean vector of the prior for $\stackrel{̄}{\gamma }$ ($K\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}1$ vector); the default value is ${\mathbf{0}}_{K}$ "P_gamma" precision matrix of the prior for $\stackrel{̄}{\gamma }$ ($K\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}K$ symmetric and positive-deﬁnite matrix); the default value is $0.001\phantom{\rule{0.3em}{0ex}}\cdot \phantom{\rule{0.3em}{0ex}}{\mathbf{I}}_{K}$ "V" scale matrix of the prior for $\Omega$ ($K\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}K$ symmetric and positive-deﬁnite matrix); the default value is $\frac{100}{K}\phantom{\rule{0.3em}{0ex}}\cdot \phantom{\rule{0.3em}{0ex}}{\mathbf{I}}_{K}$ "n" degrees-of-freedom parameter of the prior for $\Omega$ (real number greater than or equal to $K$); the default value is ${K}^{2}$ "m_beta" mean vector of the prior for $\beta$ ($L\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}1$ vector); the default value is ${\mathbf{0}}_{L}$ "P_beta" precision matrix of the prior for $\beta$ ($L\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}L$ symmetric and positive-deﬁnite matrix); the default value is $0.001\phantom{\rule{0.3em}{0ex}}\cdot \phantom{\rule{0.3em}{0ex}}{\mathbf{I}}_{L}$ "a_tau" shape parameter of the prior for $\tau$ (positive number); the default value is $0.001$ "b_tau" rate parameter of the prior for $\tau$ (positive number); the default value is $0.001$ Dataset and log-marginal likelihood "dataset" the id value of the dataset that will be used for estimation; the default value is the ﬁrst dataset in memory (in alphabetical order) "logML_CJ" boolean indicating whether the Chib (1995)/Chib & Jeliazkov (2001) approximation to the log-marginal likelihood should be calculated (true$|$false); the default value is false

Reported Parameters

 $\stackrel{̄}{\gamma }$ variable_name vector of parameters associated with the independent variables in the z list; these are the means of the group-speciﬁc parameters $\beta$ variable_name vector of parameters associated with the independent variables in the x list $\tau$ tau precision parameter of the error term, ${𝜀}_{i}$ ${\sigma }_{𝜀}$ sigma_e standard deviation of the error term: ${\sigma }_{𝜀}=1∕{\tau }^{1∕2}$

Stored values and post-estimation analysis
If a left-hand-side id value is provided when a random-coeﬃcients linear model is created, then the following results are saved in the model item and are accessible via the ‘.’ operator:

 Samples a matrix containing the draws from the posterior of $\stackrel{̄}{\gamma }$, $\beta$, $\tau$ and the unique elements of $\Omega$ z1,$\dots$,zK vectors containing the draws from the posterior of the mean of the group-speciﬁc coeﬃcients ($\stackrel{̄}{\gamma }$s) associated with variables z1,$\dots$,zK (the names of these vectors are the names of the variables that were included in the right-hand side of the model) x1,$\dots$,xL vectors containing the draws from the posterior of the parameters associated with variables x1,$\dots$,xL (the names of these vectors are the names of the variables that were included in the right-hand side of the model) tau vector containing the draws from the posterior of $\tau$ Omega_i_j vectors containing the draws from the posterior of the unique elements of $\Omega$; because $\Omega$ is symmetric, only $\frac{\left(K-1\right)K}{2}\phantom{\rule{0.3em}{0ex}}+\phantom{\rule{0.3em}{0ex}}K$ of its elements are stored (instead of all ${K}^{2}$ elements); i and j index the row and column of $\Omega$, respectively, at which the corresponding element is located Omega $K\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}K$ matrix that stores the posterior mean of $\Omega$ logML the Lewis & Raftery (1997) approximation of the log-marginal likelihood logML_CJ the Chib (1995)/Chib & Jeliazkov (2001) approximation to the log-marginal likelihood; this is available only if the model was estimated with the "logML_CJ"=true option gamma_i $N\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}K$ matrix that stores the group-speciﬁc coeﬃcients for the variables in the z list; the values in this matrix are not guaranteed to be in the same order as the order in which the groups appear in the dataset used for estimation; use the store() function to associate the values in gamma_i with the observations in the dataset nchains the number of chains that were used to estimate the model nburnin the number of burn-in draws per chain that were used when estimating the model ndraws the total number of retained draws from the posterior ($=$chains $\cdot$ draws) nthin value of the thinning parameter that was used when estimating the model nseed value of the seed for the random-number generator that was used when estimating the model

Additionally, the following functions are available for post-estimation analysis (see section B.14):

• diagnostics()
• test()
• pmp()
• store()

The random-coeﬃcients linear model uses the store() function to associate the group-speciﬁc parameters (gamma_i) with speciﬁc observations and store their values in the dataset used for estimation. The generic syntax for a statement involving the store() function after estimation of a random-coeﬃcients linear model is:

store( gamma_i, <new variable name prefix>, $\left[$"model"=<model name>$\right]$ );

This statement will generate $K$ additional variables in the dataset used for estimation of the random-coeﬃcients model, with names constructed by prepending the preﬁx provided as the second argument to store() to the names of the variables which are associated with group-speciﬁc coeﬃcients.

Examples

Example 1

myData = import("$BayESHOME/Datasets/dataset2.csv", ","); myData.constant = ones(rows(myData), 1); set_pd( year, id, "dataset" = myData); // all rhs variables are associated with group-specific coefficients lm_rc( y ~ constant x1 x2 x3); Example 2 myData = import("$BayESHOME/Datasets/dataset2.csv", ",");
myData.constant = ones(rows(myData), 1);
set_pd( year, id, "dataset" = myData);

// only the constant term and the coefficient associated with x1 are
// group-specific; the coefficients on x2 and x3 are common to all groups
lm_rc( y ~ constant x1 $|$ x2 x3);

Example 3

myData = import("\$BayESHOME/Datasets/dataset2.csv", ",");
myData.constant = ones(rows(myData), 1);
set_pd( year, id, "dataset" = myData);

// all rhs variables are associated with group-specific coefficients
model1 = lm_rc(y ~ constant x1 x2 x3,
"burnin"=10000, "draws"=40000, "thin"=4, "chains"=2,
"logML_CJ" = true, "dataset"=myData);
store( gamma_i, rc1_, "model" = model1 );

// only the constant term and the coefficient associated with x1 are
// group-specific; the coefficients on x2 and x3 are common to all groups
model2 = lm_rc( y ~ constant x1 $|$ x2 x3,
"burnin"=10000, "draws"=40000, "thin"=4, "chains"=2,
"logML_CJ" = true, "dataset"=myData);
store( gamma_i, rc2_, "model" = model2 );

pmp( { model1, model2 } );

4Optional arguments are always given in option-value pairs (eg. "chains"=3).    