Announcement

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

  • Common instances in a panel

    Hi all,

    I have the following problem to solve. Basically, I have a panel of products belonging to Molecules belonging to Countries observed by quarters. The panel is unbalanced. Since dataex provides a too short sample to understand the structure I will try to make a fake data example myself:

    Code:
     
    Product   Molecule  Country.  quarter
    A.                X            ITA        2010Q1
    A                 X            ITA        2010Q2
    A                 X            ITA        2014Q3
    A                 X            ITA        2014Q4
    A                 X            ITA        2018Q2
    A                 X            ITA        2018Q3
    B                 X            ITA        2018Q2
    B                 X           ITA         2018Q3
    B                 X           ITA         2018Q4
    C                Y            ITA         2009Q2
    C                 Y           ITA         2009Q3
    F                Z           ITA        2010Q1
    F                 Z           ITA        2010Q2
    F                 Z           ITA         2011Q1
    ...
    A.                X            USA        2010Q1
    A                 X            USA        2009Q3
    A                 X            USA        2014Q3
    A                 X            USA        2014Q4
    B                 X            USA        2016Q2
    B                 X            USA        2016Q3
    B                 X            USA        2017Q1
    B                 X           USA         2017Q2
    F                 Z           USA         2010Q1
    F                 Z           USA         2010Q2
    F                 Z           USA         2011Q1
    ...
    A.                X            AUS        2008Q1
    B                 X            AUS        2008Q2
    B                 X            AUS        2014Q3
    B                 X            AUS       2015Q4
    D                W            AUS        2016Q1
    F                Z           AUS        2010Q1
    F                 Z           AUS        2010Q2
    F                 Z           AUS         2011Q1
    K                 G           AUS         2012Q1
    K                 G          AUS         2012Q4
    K                G           AUS         2013Q1
    ...
    1) What I would like to output are the Molecules that are in common to each country and have at least "n" quarters in common.
    So in the toy example above, say I would like to output the Molecules in common between ITA, USA and AUS having at least 3 quarters in common. The output should be something like this:

    Code:
    Product   Molecule  Country.  quarter
    A.                X            ITA        2010Q1
    A                 X            ITA        2010Q2
    A                 X            ITA        2014Q3
    A.                X            USA        2010Q1
    A                 X            USA        2010Q2
    A                 X            USA        2014Q3
    A.                X            AUS        2010Q1
    A                 X            AUS        2010Q2
    A                 X            AUS        2014Q3
    F                Z           AUS        2010Q1
    F                 Z           AUS        2010Q2
    F                 Z           AUS         2011Q1
    F                Z           USA        2010Q1
    F                 Z           USA        2010Q2
    F                 Z           USA         2011Q1
    F                Z           ITA        2010Q1
    F                 Z           ITA        2010Q2
    F                 Z           ITA         2011Q1
    2) Furthermore, another thing I would like to do is to simply output the Molecule having the same number of quarters for each country (not necessarily in common). SO, again following the toy example the result should be something like:

    Code:
    Product   Molecule  Country.  quarter
    A.                X            ITA        2010Q1
    A                 X            ITA        2010Q2
    A                 X            ITA        2014Q3
    A.                X            USA        2010Q1
    A                 X            USA        2010Q2
    A                 X            USA        2014Q3
    A.                X            AUS        2010Q1
    A                 X            AUS        2010Q2
    A                 X            AUS        2014Q3
    F                Z           AUS        2010Q1
    F                 Z           AUS        2010Q2
    F                 Z           AUS         2011Q1
    F                Z           USA        2010Q1
    F                 Z           USA        2010Q2
    F                 Z           USA         2011Q1
    F                Z           ITA        2010Q1
    F                 Z           ITA        2010Q2
    F                 Z           ITA         2011Q1
    B                 X            AUS        2008Q2
    B                 X            AUS        2014Q3
    B                 X            AUS       2015Q4
    B                 X            USA        2016Q2
    B                 X            USA        2016Q3
    B                 X            USA       2017Q1
    B                 X            ITA        2018Q2
    B                 X            ITA        2018Q3
    B                 X            ITA       2018Q4
    Thank you


Working...
X