extractYear: Impute panel data

Description Usage Arguments Details Value See Also Examples

View source: R/coin_assemble.R

Description

Given a data frame of the IndData format, with a Year column, imputes any missing data using the latest available year. This function is used inside assemble().

Usage

1
extractYear(use_year, IndData, impute_latest = FALSE)

Arguments

use_year

The year of data to extract and impute.

IndData

A data frame of indicator data, containing a Year column and with multiple observations for each unit code.

impute_latest

Logical: if TRUE, imputes missing data points using most recent value from previous years. If FALSE (default) simply extracts the data frame as is.

Details

This expects a data frame in the IndData format, i.e. it should at least have a UnitCode column, and a Year column, as well as other columns that are to be imputed. It also presumes that there are multiple observations for each unit code, i.e. one per year. It then searches for any missing values in the target year, and replaces them with the equivalent points from previous years. It will replace using the most recently available point.

Value

A list containing:

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# artificial example using ASEM data
# We only have one year of data so we copy it and "pretend" that they are from different years
# First, introduce 3 NAs
dat2018 <- ASEMIndData
dat2018[2, 12] <- NA
dat2018[3, 13] <- NA
dat2018[4, 14] <- NA
# Now make copy, pretending it is the previous year
dat2017 <- ASEMIndData
dat2017$Year <- 2017
# This df still has one missing point
dat2017[4, 14] <- NA
# Finally we have a 2016 data frame where none of the previous points are missing
dat2016 <- ASEMIndData
dat2016$Year <- 2016
# We can now put them together
IndData <- rbind(dat2018, dat2017, dat2016)
# And extract the 2018 data, with missing data taken from previous years
Imp <- extractYear(2018, IndData, impute_latest = TRUE)
# View which points have been imputed and the years of data used
Imp$ImpTable

COINr documentation built on Nov. 30, 2021, 9:06 a.m.