Announcement

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

  • graph with number of company's per country per month

    Hi Stata experts,

    I am working with a panel dataset.
    I want to plot a graph with the number of company's per country per month. I have a database with almost all european countries, but I want to make a graph conntaining four lines:
    1. total company's each month
    2. number of company's UK each month
    3. number of company's Germany each month
    4. number of company's in Italy each month
    I want the axis to contain mofd and the y to contain de number of company's (stocks).

    My data looks like this: where country has a country code (so f.e. UK =GB and Germany = BD), Code is the code for a specific company and mofd contains month in stata language.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str6 Code str2 Country float mofd
    "87380E" "PL" 637
    "87380E" "PL" 638
    "87380E" "PL" 639
    "87380E" "PL" 640
    "87380E" "PL" 641
    "87380E" "PL" 642
    "87380E" "PL" 643
    "87380E" "PL" 644
    "87380E" "PL" 645
    "87380E" "PL" 646
    "87380E" "PL" 647
    "87380E" "PL" 648
    "87380E" "PL" 649
    "87380E" "PL" 650
    "87380E" "PL" 651
    "87380E" "PL" 652
    "87380E" "PL" 653
    "87380E" "PL" 654
    "87380E" "PL" 655
    "87380E" "PL" 656
    end
    format %tm mofd
    So this would be a company from Poland.

    I hope you can help me. Thanks a lot.

  • #2
    There are nuances here such as whether a company can be in several countries at once. For simplicity I assume not.

    The number of distinct companies each month is

    Code:
    egen tag = tag(Code mofd) 
    
    egen distinct = total(tag), by(mofd)
    The number in any particular country such as DE is

    Code:
    egen distinct_DE = total(tag * (Country == "DE")), by(mofd)
    For graphics you want only one observation per month

    Code:
    egen toshow = tag(mofd) 
    
    line distinct distinct_DE mofd if toshow, sort
    and so on.

    For more explanation see http://www.stata-journal.com/article...article=dm0042 -- especially p.563

    https://oneminuteenglish.org/en/companys-companies/

    Comment


    • #3
      Thank you so much.
      It worked perfectly.

      Another (maybe stupid) question. Stata always gives a fairly simplified graph. I like the lines to 'wiggle' and touch every month's observation. Is there a way I can change my graph like this?
      I looked at the graph options but I couldn't find it myself.

      Comment


      • #4
        You may need to give more details of your graph puzzle. But in principle if there are gaps in your data then Stata can't see data points to plot. If there are no firms in the dataset for a particular country and code and month, say, then they won't show up as zeros, as there are no corresponding observations. The answer is to use fillin if that is the problem.

        Comment

        Working...
        X