Announcement

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

  • Calculate export times using custom data

    HTML Code:
    clear
    input str10 company_name str3 country int year
    "3Mcompany"  "USA" 2002
    "3Mcompany"  "USA" 2002
    "3Mcompany"  "USA" 2003
    "3Mcompany"  "USA" 2004
    "3Mcompany"  "USA" 2005
    "3Mcompany"  "USA" 2007
    "3Mcompany"  "USA" 2008
    "3Mcompany"  "USA" 2009
    "3Mcompany"  "USA" 2010
    "3Mcompany2" "DEU" 2003
    "3Mcompany2" "DEU" 2003
    "3Mcompany2" "DEU" 2004
    "3Mcompany2" "DEU" 2005
    "3Mcompany2" "DEU" 2007
    "3Mcompany2" "DEU" 2009
    "3Mcompany2" "FRA" 2003
    "3Mcompany2" "FRA" 2004
    "3Mcompany2" "FRA" 2005
    end
    The original data format.
    Click image for larger version

Name:	1.png
Views:	1
Size:	42.5 KB
ID:	1573391




    And the finally data format like this pacture.
    Click image for larger version

Name:	2.png
Views:	1
Size:	57.1 KB
ID:	1573392




    Explanation:
    total_times:company A exist in country B of different year
    period_times: If year in 2002 to 2005 without interruption is 1 period.
    first_period_times:How many times in first period_times.
    How to use stata code to achieve it.
    Last edited by Carle Tong; 19 Sep 2020, 01:09.

  • #2
    Welcome to Stata list. You will increase your chances of useful answer by following the FAQ for asking questions – provide Stata code in code delimiters, readable Stata output, and sample data using dataex.

    I simply don't understand what you are trying to do. If I guess at what you want, this is what I get. At least for total times by year, you can use
    bysort company year: egen times=count(year)

    The year within the brackets is simply to give something that Stata can count.

    You probably can do the period times pretty much the same way just adding an if statement to limit the sample used to those years.

    bysort company year: egen times=count(year) if year<2006


    Comment

    Working...
    X