Nisha Malhotra
> I am facing a problem creating a binary variable. I have a large
panel data
> set. The three important variables are Year, Industry, Action taken
by an
> industry ( variable that takes the value 0 if no action was taken
and 1 if one
> action was taken and 2 if two actions were taken and so on )
>
> The data looks something like this
> Year Industry Action
> 90 A 0
> 91 A 0
> 92 A 2
> 93 A 0
> 90 B 1
> 91 B 0
> 92 B 0
> 93 B 1
>
> I want to create a binary variable say BB, which takes the value 0
if no prior
> action(in the previous years) has been taken by an industry and 1 if
some
> positive action has been taken by an industry in the previous years.
>
> Year Industry Action BB
> 90 A 0 0
> 91 A 0 0
> 92 A 2 1
> 93 A 0 1
> 90 B 1 1
> 91 B 0 1
> 92 B 0 1
> 93 B 1 1
. tsset Industry year
Note that if Industry is really string, you must -encode- it
first and use the encoded version as panel variable.
. gen byte BB = L.Action > 0 & L.Action < .
Here the attitude over the first value of BB for each
Industry differs from your example.
Nick
[email protected]
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/