My data set has three variables: year, company, and profit. How can I generate a new variable, say pchange, which would contain percentage change in profit for each company on a yearly basis?
I tried the following code.
Is it the right approach?
I tried the following code.
Code:
. sort company year . bysort company:gen pchange=100*(profit[_n]-profit[_n-1])/profit[_n-1]
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str1 company float(profit year) "A" 100 1990 "B" 1000 1990 "C" 10 1990 "D" 500 1990 "E" 700 1990 "F" 80 1990 "G" 900 1990 "H" 60 1990 "I" 50 1990 "A" 700 1991 "B" 80 1991 "C" 900 1991 "D" 60 1991 "E" 50 1991 "F" 100 1991 "G" 1000 1991 "H" 10 1991 "I" 500 1991 "J" 700 1991 "A" 80 1992 "B" 500 1992 "C" 700 1992 "D" 80 1992 "E" 900 1992 "F" 60 1992 "G" 50 1992 "H" 700 1992 "I" 80 1992 "J" 900 1992 "K" 60 1992 "A" 80 1993 "B" 900 1993 "C" 60 1993 "D" 50 1993 "E" 100 1993 "F" 1000 1993 "G" 10 1993 "H" 500 1993 "J" 700 1993 "K" 80 1993 "A" 900 1994 "B" 60 1994 "C" 80 1994 "D" 900 1994 "E" 60 1994 "F" 50 1994 "G" 100 1994 "H" 1000 1994 "J" 10 1994 "K" 500 1994 "L" 700 1994 "A" 80 1995 "B" 80 1995 "C" 900 1995 "D" 60 1995 "E" 50 1995 "F" 100 1995 "G" 1000 1995 "H" 10 1995 "J" 500 1995 "K" 700 1995 "L" 80 1995 end
Comment