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?
Bootstrap for difference in proportionsDoes anyone know how to bootstrap the 95CI and obtain the p-value for the difference in proportion o…
Event repetition dummyHello, I need to create two dummies based on the events arrangement frequency repetition rule . Eve…
How to calculate the difference beween values in the first and last waves of an unbalanced panel?I have an unbalanced panel of scores for a test done monthly at different points in time. I want to …
Merging datasetHi, I want to ask a question on merging dataset. My Master dataset looks like an example given belo…
How do you identify ICD-10-CM codes in Nationwide Inpatient Sample (NIS) using STATA?NIS has 40 Diagnoses (dx1 to dx40) listed for every patient. I am trying to find how many have diabe…
Subscribe to:
Post Comments (Atom)
0 Response to local macro to be used for numlist?
Post a Comment