Dear all,

I have the following dataset.
I am trying to create a variable that generates 1 when the % of ownership of a firm increases and 0 for the rest (that is % of ownership remains the same or decrease).
I tried the following code which kind of work but it indicates the number of change in the % of ownership (ie. 1,2,3 and so on) regardless if it increases or decreases.

by permno year (ownership), sort: gen increase = sum(ownership~=ownership[_n-1] & _n~=1)

permno year ownership increase
05236 2015 36.3 1
05236 2015 36.3 1
05236 2015 36.3 1
05236 2015 36.3 1
05236 2015 37 2
05236 2015 37 2
05236 2015 37 2
05236 2015 37 2
05236 2015 37 2
05236 2015 37 2
05236 2015 38 3
05236 2015 38 3