|
楼主

楼主 |
发表于 2011-7-24 10:34:26
|
只看该作者
Help about creating a dummy
I have a question on creating a dummy if it is satisfied with a certain condition.
Here is the data I have:
firm year x1
A 1985 0
A 1986 0
A 1987 0
A 1988 0
A 1989 1
A 1990 1
A 1991 1
A 1992 1
A 1993 1
A 1994 1
B 1991 1
B 1992 1
B 1993 1
B 1994 1
B 1995 1
B 1996 0
B 1997 0
B 1998 0
B 1999 0
B 2000 0
C 1999 1
C 2000 1
C 2001 1
C 2002 0
C 2003 0
C 2004 0
C 2005 0
C 2006 0
D 1977 0
D 1978 0
D 1979 0
D 1980 0
D 1981 0
D 1982 0
D 1983 0
D 1984 0
D 1985 0
I want to create a dummy variable depending on the variable x1.So,
like A company, the x1 variable starts with 0 and switch to 1 in later years. I would like to create a dummy equals to 2.
For B company, the x1 variable starts with 1 and switch to 0 in later years. I would like to have a dummy equals to 1.Again, for C company, the x1 variables starts with 1 and switch to 0 in later years. I would like to have a dummy equals to 1.
For D company, it never switches. So I will like the dummy equals to 3.
So the data I want will look like the following:
firm year x1 dummy
A 1985 0 2
A 1986 0 2
A 1987 0 2
A 1988 0 2
A 1989 1 2
A 1990 1 2
A 1991 1 2
A 1992 1 2
A 1993 1 2
A 1994 1 2
B 1991 1 1
B 1992 1 1
B 1993 1 1
B 1994 1 1
B 1995 1 1
B 1996 0 1
B 1997 0 1
B 1998 0 1
B 1999 0 1
B 2000 0 1
C 1999 1 1
C 2000 1 1
C 2001 1 1
C 2002 0 1
C 2003 0 1
C 2004 0 1
C 2005 0 1
C 2006 0 1
D 1977 0 3
D 1978 0 3
D 1979 0 3
D 1980 0 3
D 1981 0 3
D 1982 0 3
D 1983 0 3
D 1984 0 3
D 1985 0 3
The years for every company could be different but I do not worry about when the company switch. But I want to identify it when there is a switch for a given company.
Could anyone help me on this issue? Thanks in advance! |
|