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?
Creating table with many simple linear regression (regress) outputsHello. This is my first post here so please feel free to give suggestions on how to format the post,…
Aggregating oaxaca decompositions of functions of the same variableDear all, Hope you are having a wonderful day! I have a question regarding how to aggregate oaxaca …
Reshaping long to wide data with multiple unique identifier in a data setDear all, I faced a problem while using reshape command for my data. reshape wide time_from time_t…
kountry commandHi all, I'm trying to generate iso2 codes for all countries (typed out manually) and I have been tol…
kountry commandHi all, I'm trying to generate iso2 codes for all countries (typed out manually) and I have been tol…
Subscribe to:
Post Comments (Atom)
0 Response to local macro to be used for numlist?
Post a Comment