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
Related Posts with gen with differences between observations
Stata extract year from dateMy data has a date variable, and I want to extract year, month, date information from it: date 03ju…
Cleaning challenge blanks in variablesHello when reshaping data, from long to wide, we wanted to make each row per director, and all the …
2 identical values between any two columnsHello. I have a file with about 30 columns of integers. I need to create a dummy variable that indic…
Identify first time dummy variable = 1 across observations in a panel data setHello! This is my first time asking a question on here, so please excuse me if it is phrased incorre…
What kind of interpolating should I use?I have a daily dataset with global aggregate numbers of an index and a monthly index of countries sp…
Subscribe to:
Post Comments (Atom)
0 Response to gen with differences between observations
Post a Comment