Right now my data looks something like this. What I want to do is to fill in the missing values in logrd with logrd[_n+1]-avgrdgr[_n+1].
age avgrdgr logrd
-37 0.1 .
...
-3 -0.2 .
-2 -0.1 .
-1 0.3 .
0 0.4 .
1 0.1 .
2 0.6 .
3 0.5 1
So the result should look like this...
age avgrdgr logrd
-37 0.1 0.3
...
-3 -0.2 -0.8
-2 -0.1 -0.9
-1 0.3 -0.6
0 0.4 -0.2
1 0.1 -0.1
2 0.6 0.5
3 0.5 1
I tried looping it by creating a code like this.
foreach x of logrd & y of avgrdgr{
if missing(`x'){
bys cus: replace `x' = `x'[_n+1] - `y'[_n+1]
}
}
This is my first time actually trying to create a loop all by myself and I am stuck.. please help me.