Announcement

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

  • Drop variable by period of time

    Dear statalist,

    I have a list of companies and variables (hereafter) where isin identifies different companies, year and dates. Some companies (same isin) appears different times in the sample. I want to have a difference of more than 180 days if two ccompanies have the same isin. So I want to drop the companies with the same isin when the difference between two dates is less than 180 days I tried the comman bygroup and count but I don't manage to get what I want.



    Thank a lot for your answers;
    Najiba




    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str28 company int year str14(isin date)
    "Michelin"              2009 "FR0000121261"   " 6/17/2009"    
    "Total"                 2009 "FR0000120271"   " 3/10/2009"    
    "Accor"                 2009 "FR0000120271"   " 6/30/2009"    
    "Air France"            2009 "FR0000031122 "  " 2/13/2009"    
    "Air France"            2009 "FR0000031122 "  " 4/15/2009"    
    "Air France"            2009 "FR0000031122 "  "  9/4/2009"    
    "Air Liquide"           2009 "FR0000120073"   "10/18/2009"    
    "ARKEMA"                2009 "FR0010313833"   "10/22/2009"    
    "Alcaltel Lucent"       2009 "FR0000130007"   " 2/11/2009"    
    "Idestylealten"         2009 "FR0000071946"   "10/16/2009"    
    "Altran"                2009 "FR0000034639"   " 6/18/2009"    
    "Atos"                  2009 "FR0000051732"   " 2/18/2009"    
    "Beneteau"              2009 "FR0000035164"   "  4/2/2009"    
    "Club Med "             2009 "FR0000121568"   " 6/26/2009"    
    "Eramet"                2009 "FR0000131757"   "  8/5/2009"    
    "FAURECIA SE"           2009 "FR0000121147"   "  2/5/2009"    
    "Flo goupe"             2009 "FR0004076891"   "  3/6/2009"    
    "France Telecom"        2009 "FR0000133308"   "  3/4/2009"    
    "France champi"         2009 "FR0000063935"   " 8/27/2009"    
    "Indeix multimed"       2009 "FR0004061513"   " 1/23/2009"    
    "3 SUISSE"              2009 "FR0000121485"   " 2/11/2009"    
    "OENEO"                 2009 "FR0000052680"   "  2/5/2009"    
    "L'oréal "              2009 "FR0000120321"   " 2/17/2009"    
    "Fnac "                 2009 "FR0011476928"   " 2/18/2009"    
    "LA RECOUTE"            2009 "FR0000121485"   " 10/5/2009"    
    "Manitou"               2009 "FR0000038606"   "  4/2/2009"    
    "Latécoère"             2009 "FR0000032278"   " 9/16/2009"    
    "LVMH"                  2009 "FR0000121014"   "  2/6/2009"    
    "Marriaunuad"           2009 "FR0000064941"   " 6/15/2009"    
    "nexans"                2009 "FR0000044448 "  " 9/18/2009"    
    "NEXTRADIO"             2009 "FR0010240994"   " 2/13/3009"    
    "PCAS"                  2009 "FR0000053514"   " 4/16/2009"    
    "PLASTIVALOIRE"         2009 "FR0000051377"   " 3/25/2009"    
    "RHODI"                 2009 "FR0010479956"   " 3/20/2009"    
    "ROCAMET"               2009 "FR0000064255"   " 1/31/2009"    
    "SAINT GOBAIN"          2009 "FR0000125007"   "  9/8/2009"    
    "SAFRAN"                2009 "FR0000073272"   "  7/9/2009"    
    "SANOFI"                2009 "FR0000120578"   " 6/30/2009"    
    "SELECTRIC"             2009 "FR0000121972 "  " 1/29/2009"    
    "SEB"                   2009 "FR0000121709"   " 2/11/2009"    
    "SEQUANA"               2009 "FR0000063364"   " 7/27/2009"    
    "SOITEC"                2009 "FR0013227113"   "  4/2/2009"    
    "SPIR COMM"             2009 "FR0000131732"   " 1/29/2009"    
    "ST DUPONF"             2009 "FR0000054199"   " 6/16/2009"    
    "TAHLES"                2009 "FR0000121329 "  "  7/1/2009"    
    "teleperfomrance"       2009 "FR0000051807"   " 6/16/2009"    
    "VALEO"                 2009 "FR0013176526"   " 1/15/2009"    
    "VEDIOR"                2009 "FR0000077570"   "  1/9/2009"    
    "REDOUTE"               2009 "FR0000121485"   " 2/11/2009"    
    "FNAX"                  2009 "FR0000121485"   "  3/4/2009"    
    "Air Liquide"           2009 "FR0000120073"   " 3/27/2009"    
    "Alcaltel Lucent"       2009 "FR0000130007"   "  7/1/2009"    
    "ARKEMA"                2009 "FR0010313833 "  " 3/11/2009"    
    "ARKEMA"                2009 "FR0010313833 "  "  9/1/2009"    
    "ARKEMA"                2009 "FR0010313833 "  " 11/6/2009"    
    "Latécoère"             2009 "FR0000032278"   "  6/3/2009"    
    "LVMH ZENITH"           2009 "FR0000121014"   " 6/12/2009"    
    "VALEO"                 2009 "FR0013176526"   " 1/16/2009"    
    "VALEO"                 2009 "FR0013176526"   " 1/10/2009"    
    "VALEO"                 2009 "FR0013176526"   "  3/3/2009"    
    "BOURBON"               2009 "FR0004548873"   " 7/30/2009"    
    "AUGROS"                2009 "FR0000061780"   " 1/12/2009"    
    "SAFT"                  2009 "FR0010208165"   "70CT OU 10SEPT"
    "EXCEL INDUSTRIE"       2009 "FR0004527638"   "  5/1/2009"    
    "HIOLLES"               2009 "FR0000077562"   "12/18/2009"    
    "ESPACE PROD"           2009 "FR0004048072"   " 5/28/2009"    
    "PONCIN YACHT"          2009 "FR0010193052 "  "  8/1/2009"    
    "CHARGEURS"             2009 "FR0000130692 /" " 5/15/2009"    
    "INFOVISTA"             2009 "FR0004031649"   " 2/12/2009"    
    "FAURECIA SE"           2009 "FR0000121147"   "  2/5/2009"    
    "FRANDCE TELECIM"       2009 "FR0000133308."  " 1/15/2009"    
    "RHODIA "               2009 "FR0010479956"   " 2/23/2009"    
    "RHODIA "               2009 "FR0010479956"   " 3/20/2009"    
    "RHODIA "               2009 "FR0010479956"   "  5/6/2009"    
    "overlap"               2009 "FR0010759530"   " 5/16/2009"    
    "TOTALENERGIES SE"      2010 "FR0000120271"   " 1/21/2010"    
    "NICOX SA"              2010 "FR0013018124"   " 12/1/2010"    
    "EVERGREEN SA"          2010 "FR0000035784"   " 2/23/2010"    
    "TECHNICOLOR SA"        2010 "FR0013505062"   " 3/31/2010"    
    "REMY COINTREAU"        2010 "FR0000130395"   "  2/5/2010"    
    "GROUPE ADP"            2010 "FR0010340141"   " 7/26/2010"    
    "SANOFI"                2010 "FR0000120578"   " 3/31/2010"    
    "PEUGEOT"               2010 "FR0000121501"   " 4/13/2010"    
    "AVENIR TELECOM"        2010 "FR0013529815"   "  2/4/2010"    
    "TELEPERFORMANCE"       2010 "FR0000051807"   "  7/1/2010"    
    "GROUPE GORGE"          2010 "FR0000062671"   " 6/25/2010"    
    "ACTIA GROUP"           2010 "FR0000076655"   "10/21/2010"    
    "GROUPE LDC"            2010 "FR0013204336"   " 4/22/2010"    
    "ALSTOM SA"             2010 "FR0010220475"   " 10/4/2010"    
    "RISC GROUP"            2010 "FR0004038248"   "  2/9/2010"    
    "vinci"                 2010 "FR0000125486"   "  4/4/2010"    
    "norbert dentressengle" 2010 "FR0000052870"   "12/16/2010"    
    "THALES"                2010 "FR0000121329"   "11/25/2010"    
    "Air France"            2010 "FR0000031122"   "  7/5/2010"    
    "SELECTRIC"             2010 "FR0000121972"   " 3/31/2010"    
    "renault"               2010 "FR0000131906"   "11/23/2010"    
    "SPIR COMM"             2010 "FR0000131732"   "  3/1/2010"    
    "psa"                   2010 "FR0000121501"   "11/18/2010"    
    "sanofi"                2010 "FR0000120578"   " 12/6/2010"    
    "maison valerie"        2010 ""               " 2/24/2010"    
    end

  • #2
    Najiba:
    your dataset needs a bit of surgery, as some firms seem to be entered twice with different names (say, -Peugeot- and PSA): hence, a consistence double-check is mandatory to avoid unsormountable problems when it comes to data analysis.
    That said, what follows should approch what you've in mind:
    Code:
    . gen new_date=date( date , "MDY")
    . format new_date %td
    . replace isin=strtrim( isin)
    . encode isin,g(n_isin)
    . bysort n_isin (year): gen diff= new_date[_n]- new_date[_n-1]
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment

    Working...
    X