Consider the following example describing a panel data set:
Using this data, I have generated a matrix containing the first-and second-difference of V.
Here, I want to combine the two columns without missing values like below:
A solution I found is
However, I think, there could be a more tidy way to combine the column vectors.
Do you have some good ideas?
Code:
clear all version 18 mata: N = 100 T = 3 pid = (1::N) # J(T, 1, 1) tid = J(N, 1, 1::T) V = rnormal(N * T, 1, 0, 1) nvs = st_addvar("double", ("pid", "tid", "V")) st_addobs(length(V) - st_nobs()) st_store(., nvs, (pid, tid, V)) end xtset pid tid
Code:
mata: st_view(dV = ., ., "S" :+ strofreal((1, 2)) :+ "." :+ "V") mata: dV[1::9, ] 1 2 +-------------------------------+ 1 | . . | 2 | 1.743666979 . | 3 | 1.124789274 2.868456253 | 4 | . . | 5 | -1.05772296 . | 6 | .4311303958 -.6265925644 | 7 | . . | 8 | -.2559339912 . | 9 | 1.213522593 .9575886021 | +-------------------------------+
Code:
1 +----------------+ 1 | 1.743666979 | 2 | 1.124789274 | 3 | 2.868456253 | 4 | -1.05772296 | 5 | .4311303958 | 6 | -.6265925644 | 7 | -.2559339912 | 8 | 1.213522593 | 9 | .9575886021 | +----------------+
Code:
mata: Vt = colshape(dV[, ], cols(dV) * 3) mata: colshape((Vt[, 3], Vt[, 5], Vt[, 6]), 1)
Do you have some good ideas?