Dear All,
Task: Variable X has a lot of missing values, suppose the first three values are missing, and for each non-missing values, say, the fifth observation of X, X[5] is non-missing, I want to replace X[3] by X[5], and such operation holds for all the non-missing values.
My inefficient solution looks like the following:
1. Identify the location of the non-missing value of X
gen index = _n if !missing(X)
list index if !missing(index)
e.g., it gives two numbers, say 34, 44 , then I key-in the number 32 and 42 in the following loop
2. foreach a of numlist 32 42 {
replace X = X[`a'+2] in `a'
}
I am wondering how to avoid keying in the numbers 32 and 42 in the above foreach loop since if numlist containing a lot of numbers, this obviously becomes infeasible
Thank you very much for your help.
Dong
Related Posts with local macro to be used for numlist?
Dynamic Panel threshold modelI am writing a paper applying a dynamic panel threshold model. however, I am not sure if I apply cor…
How replace text value of variable with numberSo I have a variable education that has lots of values in text specifying 'bachelor 1', 'bachelor 2'…
Interpreting Stata's R^2 and rho in a fixed effects regressionAs i understand it, the rho indicates the percentage of the variance that is due to individual fixed…
WeightingHello guys, I am trying to replicate an approach from Barber, Brad M. and Huang, Xing and Odean, Ter…
Dropping multiple variables ending within a range of numbersDear Statlist, I am currently trying to organise data from the LISS dataset. A number of variables …
Subscribe to:
Post Comments (Atom)
0 Response to local macro to be used for numlist?
Post a Comment