Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: Re: st: generating a 0,1 variable which depends on lag values (2)


From   "Nick Cox" <[email protected]>
To   <[email protected]>, <[email protected]>
Subject   RE: Re: st: generating a 0,1 variable which depends on lag values (2)
Date   Thu, 12 Sep 2002 00:08:24 +0100

I replied to 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. 

I think I misinterpreted this, as I read 
"previous years" as "previous year". 

If the precise definition is action in 
any previous year, then 

. bysort Industry (Year) : gen byte BB = sum(Action) > 0 


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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index