Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting a first time appearance of a certain value in the data

    Dear Stata Users,

    Can you please help me to generate new variable called - "first_purchase" equal to "1" if it is the first time when a firm (gvkey) has "purchase" = 1 for the first time. Like, in the data sample below gvkey = 001104 will have "purchase" = 0 since in starts having "purchase" = 1 from the beginning of the able data series. Firm = 001109 will have "purchase" = 1 (and 0 otherwise) just in 2005 since this is a day when a firm had its first purchase. Firm 001161 will have "purchase" = 0 since the earliest date available is with contract.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str24 gvkey double fyear float purchase
    "001104" 2001 1
    "001104" 2002 1
    "001104" 2003 1
    "001104" 2004 1
    "001104" 2005 0
    "001104" 2006 0
    "001104" 2007 0
    "001104" 2008 0
    "001104" 2009 0
    "001104" 2010 0
    "001104" 2011 1
    "001104" 2012 0
    "001104" 2013 0
    "001104" 2014 0
    "001104" 2015 0
    "001104" 2016 0
    "001104" 2017 0
    "001109" 2000 0
    "001109" 2001 0
    "001109" 2002 0
    "001109" 2003 0
    "001109" 2004 0
    "001109" 2005 1
    "001109" 2006 1
    "001109" 2007 1
    "001109" 2008 1
    "001161" 2001 1
    "001161" 2002 0
    "001161" 2003 0
    "001161" 2004 0
    "001161" 2005 0
    "001161" 2006 1
    "001161" 2007 0
    "001161" 2008 0
    "001161" 2009 0
    end

  • #2
    Google

    first occurrence Stata FAQ

    to find a dedicated FAQ.

    Comment


    • #3
      Thank you! I used this one - Stata | FAQ: First and last occurrences in panel data. And it helped

      Comment

      Working...
      X