estimate: estimate

Description Usage Arguments Details Author(s) See Also Examples

Description

Create STAN estimates

Usage

1
2
estimate(data = data.all, sources = est.array.d[est.array.d$est == "DET", ],
  period = c(1995:2010), isic = 3)

Arguments

data

a dataframe object

sources

a data frame with main source and secondary sources for each combination in the data

period

time period for estimation

isic

industry classification

Details

Combine extend and detail functions to time series according to supplied list of sources

Author(s)

OECD STAN

See Also

extend, detail

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
data table: cou, var, ind, year, value
sources table: cou, var, ind, est, MAIN, SEC
data.all <- stani3Estimate.data.all # source stani3Estimate.R
exportcou <- c("NOR")
exportvar <- c("VALU", "PROD")
nameind <- as.character(ui.stani3Estimate.ind)
nameest <- c("DET", "EXT")
nameyear <- c(1995:2012)
est.array <- ui.stani3Estimate.est.array[exportcou, exportvar, nameind, nameest,,drop = FALSE]
est.array.m <- melt(est.array, id.vars = c("cou", "var", "ind", "est"), variable.name = "sou")
est.array.m$ind <- factor(est.array.m$ind, levels = STANi3.INDA60All)
est.array.d <- dcast(est.array.m, cou + var + ind + est ~ sou, value.var = "value")
x <- match(unique(est.array.m$ind), names(STANi3.HIERARCHYINV))
x <- x[!is.na(x)]
ind.parent <- unique(unlist(STANi3.HIERARCHYINV[x]))
data.all <- data.all[data.all$cou%in%as.character(unique(est.array.m$cou)) &
                     data.all$var%in%unique(est.array.m$var) &
                     data.all$ind%in%union(unique(est.array.m$ind), ind.parent) &
                     data.all$year%in%nameyear &
                     data.all$sou%in%unique(unlist(strsplit(as.character(est.array.m$value), split = ", "))),]

res.ext <- NULL
data.ext <- data.all
print(est.array.d[est.array.d$est=="EXT",])
res.ext <- estimate(data=data.ext,
                    sources=est.array.d[est.array.d$est=="EXT",],
                    period=nameyear)
## add back rows from main source
sou.main.ext <- melt(ui.stani3Estimate.est.array[exportcou, exportvar, nameind, "EXT", "MAIN"])
names(sou.main.ext) <- sub("value", "sou", names(sou.main.ext))
data.all.ext.main <- merge(data.all, sou.main.ext)
res.ext <- rbind(res.ext, data.all.ext.main) # adds around 6000 rows from data.all
res.ext <- res.ext[!duplicated(res.ext[,!colnames(res.ext)%in%c("sou", "value")]),]
res.ext$sou <- "PATCHEXT"
res.ext <- rbind(res.ext, data.all)
##
res.det <- NULL
data.det <- res.ext
print(est.array.d[est.array.d$est=="DET",])
res.det <- estimate(data=data.det
                    ,
                    sources=est.array.d[est.array.d$est=="DET",]
                    ,
                    period=nameyear
                    )

res.det <- rbind(res.det, res.ext)
data.est <- rbind(res.det, res.ext)
data.est <- data.est[!duplicated(data.est[,!colnames(data.est)%in%c("sou", "value")]),]
data.est$ind <- factor(data.est$ind, levels = nameind)
data.est <- data.est[order(data.est$ind),]
data <- data.est

estimate(data=data.all, sources=est.array.d[est.array.d$est=="DET",], period=nameyear)
estimate(data=data.all, sources=est.array.d, period=nameyear)

bowerth/stan documentation built on May 13, 2019, 12:38 a.m.