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?
Heteroskedasticity - Breusch–Pagan testDear Stata community! I am running the three Breusch–Pagan tests versions most common in Stata (es…
Graph of event study for multiple regressions using eventdd packageUsing the following command and using the data, you can use an event study graph for only one set of…
Correlation between variablesHello Statalists, Please, could anyone help with the correct command? I have two datasets measuring …
extract letters from wordsDear All, Suppose that I have this data set (with variable "Journal_e": Code: * Example generated b…
Finding sum per row based on conditionsMembers, I have a dataset with multiple columns (var1, var2, var3, etc.) with missing observations.…
Subscribe to:
Post Comments (Atom)
0 Response to local macro to be used for numlist?
Post a Comment