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

View source: R/functions.R

matrices2longR Documentation

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)

Details

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

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.

Author(s)

Francesco Bartolucci, Silvia Pandolfi, Fulvia Pennoni, Alessio Farcomeni, Alessio Serafini

Examples


### 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)



LMest documentation built on Aug. 27, 2023, 5:06 p.m.