Hi everyone,
I'm having a long panel data set with 1250 individuals (identified by case) and information about their entrance into the labor market. The variable shown below "nummer_eintritt" shows, if it was the first, second, third, etc. entrance. I have a third variable "SES_" (I cannot display due to data privacy) that I now want to analyse.
For each individual, I want to generate a new variable that contains the value of SES_[_n-1] if nummer_eintritt[_n]==1, if the SES_[_n-1] is not missing. If it is missing, it should display the value of SES_ for _n-2 and so on.
I tried to get it by putting lots of conditions together, but it would end in a very high number of conditions because sometimes you have to go back 20 observations to find a non missing value.
Could you please help me on that?
Thank you and best regards
Marie
clear
input long case float nummer_eintritt
681 0
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 1
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
681 .
end
[/CODE]
Related Posts with Identifying first non-missing value based on another variable
Dynamically rename variable (using "word()")I have a dataset that looks as follows: Code: clear input str7 index int data "EOSQ041" 42…
Compare multiple regression coefficients across regression modelsHi guys, I want to compare coefficients across two different regression models. I found a useful in…
Problem with -import dbase-I am using -import dbase- to convert a DBF file to DTA. However, it is replacing some of the non-mis…
Pre-announcement driftDear Statalist, I would really apreciate any help/tips members have to offer on this topic. I am w…
Measuring change in logistic random effects modelHi! I am doing a longitudinal analysis on the effects of firm contexts/practices on employees' rela…
Subscribe to:
Post Comments (Atom)
0 Response to Identifying first non-missing value based on another variable
Post a Comment