Hello all,
I am using Stata/IC 12.1.
I have a panel data set and I need to pick the first nonmissing (and non-zero) value of the leverage variable of firms. This value is to used as a new variable "initial leverage" for each firm.
My data looks like:
id year leverage
1 1980 .
1 1981 .
1 1982 2
2 1980 5
2 1982 6
2 1983 1
3 1980 4
3 1983 .
3 1984 2
The desired result would be:
id inilev
1 2
1 2
1 2
2 5
2 5
2 5
3 4
3 4
3 4
Comments:
- years may be different within group of firms, but they do not repeat
- regardless of the magnitude, I need to get always the first nonmissing value for each firm
- the series spams from 1950-200 for over 400 firms
Previous attemps:
Searching the archives I found similar codes, but was not able to adapt to my issue.
- one case picked the minimum value
Thank you so much,
Clarice
I am using Stata/IC 12.1.
I have a panel data set and I need to pick the first nonmissing (and non-zero) value of the leverage variable of firms. This value is to used as a new variable "initial leverage" for each firm.
My data looks like:
id year leverage
1 1980 .
1 1981 .
1 1982 2
2 1980 5
2 1982 6
2 1983 1
3 1980 4
3 1983 .
3 1984 2
The desired result would be:
id inilev
1 2
1 2
1 2
2 5
2 5
2 5
3 4
3 4
3 4
Comments:
- years may be different within group of firms, but they do not repeat
- regardless of the magnitude, I need to get always the first nonmissing value for each firm
- the series spams from 1950-200 for over 400 firms
Previous attemps:
Searching the archives I found similar codes, but was not able to adapt to my issue.
- one case picked the minimum value
Code:
by id, sort: egen inilev = min(cond(!missing(leverage), leverage, .))
Clarice