Learn R Programming

LMest (version 3.0.0)

matrices2long: From data in array format to data in long format

Description

Function to convert data with array format in data with long format.

Usage

matrices2long(Y, X1 = NULL, X2 = NULL)

Arguments

Y

array of responses (n x TT x r)

X1

array of covariates (n x TT x nc1)

X2

array of covariates (n x TT x nc2)

Value

Returns a data.frame with data in long format. The first column indicates the name of the unit identifier, and the second column indicates the time occasions.

Details

Y, X1 and X2 must have the same number of observations.

Examples

Run this code
# NOT RUN {
### Example with data on self rated health

data(data_SRHS_long)
SRHS <- data_SRHS_long[1:1600,]

# Covariates

X <- cbind(SRHS$gender-1,
           SRHS$race == 2 | SRHS$race == 3,
           SRHS$education == 4,
           SRHS$education == 5,
           SRHS$age-50,
           (SRHS$age-50)^2/100)

# Responses

Y <- SRHS$srhs


res <- long2matrices(SRHS$id, X = X, Y = Y)

long <- matrices2long(Y = res$YY, X1 = res$XX)


# }

Run the code above in your browser using DataLab