Dear Stata Users,
Can you, please help me to resolve the following issue. I need to create the following variables: “pv_1”, “pv_2”, “pv_3”, “pv_4”, “pv_5”. “pv_1” should equal to 1 (for all the observations of a given firm) if a given firm(“gvkey”) has “p_v_decile” equal to 5 for at most 1 year. “pv_2” should equal to 1 (for all the observations of a given firm) if a given firm(“gvkey”) has “p_v_decile” equal to 5 for 2 consecutive years. For “pv_3”, “pv_4” the logic is the same. “pv_5” should equal to 1 (for all the observations of a given firm) if a given firm(“gvkey”) has “p_v_decile” equal to 5 at least 5 consecutive years.
In the original sample, “p_v_decile” has values from 1 to 5, but for brevity I just present “5” as an example.
Please, help me with this issue.
Can you, please help me to resolve the following issue. I need to create the following variables: “pv_1”, “pv_2”, “pv_3”, “pv_4”, “pv_5”. “pv_1” should equal to 1 (for all the observations of a given firm) if a given firm(“gvkey”) has “p_v_decile” equal to 5 for at most 1 year. “pv_2” should equal to 1 (for all the observations of a given firm) if a given firm(“gvkey”) has “p_v_decile” equal to 5 for 2 consecutive years. For “pv_3”, “pv_4” the logic is the same. “pv_5” should equal to 1 (for all the observations of a given firm) if a given firm(“gvkey”) has “p_v_decile” equal to 5 at least 5 consecutive years.
In the original sample, “p_v_decile” has values from 1 to 5, but for brevity I just present “5” as an example.
Please, help me with this issue.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str6 gvkey double fyear float p_v_decile "030029" 2012 5 "030031" 1996 5 "030034" 1995 5 "030034" 1997 5 "030066" 1996 5 "030087" 1995 5 "030087" 1996 5 "030087" 1998 5 "030087" 1999 5 "030094" 1995 5 "030094" 1996 5 "030094" 1999 5 "030095" 1995 5 "030095" 1996 5 "030095" 1997 5 "030095" 1998 5 "030130" 1996 5 "030130" 1997 5 "030131" 1996 5 "030131" 1997 5 "030131" 1998 5 "030131" 1999 5 "030137" 1997 5 "030137" 1998 5 "030137" 1999 5 "030137" 2002 5 "030137" 2003 5 "030137" 2004 5 "030137" 2005 5 "030152" 2002 5 "030152" 2003 5 "030203" 1996 5 "030203" 1998 5 "030233" 1996 5 "030233" 1998 5 "030233" 1999 5 "030259" 2004 5 "030259" 2006 5 "030259" 2007 5 "030265" 2000 5 "030277" 1999 5 "030312" 1996 5 "030312" 1998 5 "030312" 1999 5 "030312" 2012 5 "030312" 2013 5 "030312" 2014 5 "030312" 2015 5 "030344" 1996 5 "030349" 1995 5 "030349" 1996 5 "030349" 1997 5 "030352" 1999 5 "030377" 1996 5 "030398" 1996 5 "030398" 2004 5 "030398" 2005 5 "030398" 2006 5 "030398" 2007 5 "030398" 2010 5 "030400" 1998 5 "030400" 1999 5 "030422" 1996 5 "030436" 1995 5 "030477" 2002 5 "030530" 1995 5 "030530" 1997 5 "030540" 1997 5 "030545" 1996 5 "030546" 2000 5 "030554" 2000 5 "030554" 2001 5 "030554" 2002 5 "030554" 2003 5 "030576" 1995 5 "030576" 1996 5 "030576" 1997 5 "030576" 1999 5 "030034" 1998 . "030034" 1999 . "030087" 2000 . "030087" 2001 . "030087" 2002 . "030087" 2003 . "030094" 2000 . "030094" 2000 . "030094" 2001 . "030094" 2001 . "030094" 2002 . "030094" 2002 . "030203" 1999 . "030203" 2000 . "030312" 2000 . "030312" 2001 . "030312" 2002 . "030312" 2003 . "030576" 2000 . "030576" 2001 . "030576" 2002 . "030576" 2003 . end
Comment