Announcement

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

  • How to calculate Age of each firm

    Hi everyone, I am working with the firm level dataset for Spain around 87,000 firms, each of them has date of incorporation (I calculated the age of each firm depending on this variable by excel ) but I wonder is there any way to do it in Stata. The problem is here, some firms has YYYY format and some of them has DDMMYYYY format.

    Best regards,


  • #2
    Descriptions of data are well-meant but insufficient to help those who want to help you. Even the best descriptions of data are no substitute for an actual example of the data. There are many ways your data might be organized that are consistent with your description, and each would require a somewhat different approach. In order to get a helpful response, you need to show some example data.

    Be sure to use the dataex command to do this. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, dataex is already part of your official Stata installation. If not, run ssc install dataex to get it. Either way, run help dataex and read the simple instructions for using it. dataex will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment


    • #3
      Dear William, thank you for the information. After I investigate throughout the forum, I learned how to calculate the age of the firm. You can see the code below. However, I have two formats of DATE, one is with YYYY and the other one is DDMMYYYY. To overcome this issue, I used below code and created two different birth_dates and then filled the missing variables in each column.

      You can see my code here.


      gen today_date=date("`c(current_date)'","DMY")

      generate birth_date = date(DATE, "DMY")

      generate birth_date1 = date(DATE, "Y")

      generate birth_datee = cond(missing(birth_date), birth_date1, birth_date)

      format birth_datee %td

      gen age = int((today_date - birth_datee)/365.25)

      Do you think there is an easy way to do that?

      Best regards,


      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input long ID str10 DATE float(eventdate today_date birth_date birth_date1 birth_datee age)
       1 "06/04/2000" 18992 22836 14706     . 14706 22
       1 "06/04/2000" 19358 22836 14706     . 14706 22
       1 "06/04/2000" 19723 22836 14706     . 14706 22
       1 "06/04/2000" 20088 22836 14706     . 14706 22
       1 "06/04/2000" 20453 22836 14706     . 14706 22
       1 "06/04/2000" 20819 22836 14706     . 14706 22
       1 "06/04/2000" 21184 22836 14706     . 14706 22
       1 "06/04/2000" 21549 22836 14706     . 14706 22
       1 "06/04/2000" 21914 22836 14706     . 14706 22
       1 "06/04/2000" 22280 22836 14706     . 14706 22
       2 "1992"       19358 22836     . 11688 11688 30
       2 "1992"       19723 22836     . 11688 11688 30
       2 "1992"       20088 22836     . 11688 11688 30
       2 "1992"       20453 22836     . 11688 11688 30
       2 "1992"       20819 22836     . 11688 11688 30
       2 "1992"       21184 22836     . 11688 11688 30
       2 "1992"       21549 22836     . 11688 11688 30
       2 "1992"       21914 22836     . 11688 11688 30
       2 "1992"       22280 22836     . 11688 11688 30
       2 "1992"       22645 22836     . 11688 11688 30
       3 "1948"       19358 22836     . -4383 -4383 74
       3 "1948"       19723 22836     . -4383 -4383 74
       3 "1948"       20088 22836     . -4383 -4383 74
       3 "1948"       20453 22836     . -4383 -4383 74
       3 "1948"       20819 22836     . -4383 -4383 74
       3 "1948"       21184 22836     . -4383 -4383 74
       3 "1948"       21549 22836     . -4383 -4383 74
       3 "1948"       21914 22836     . -4383 -4383 74
       3 "1948"       22280 22836     . -4383 -4383 74
       3 "1948"       22645 22836     . -4383 -4383 74
       4 "30/12/1999" 18992 22836 14608     . 14608 22
       4 "30/12/1999" 19358 22836 14608     . 14608 22
       4 "30/12/1999" 19723 22836 14608     . 14608 22
       4 "30/12/1999" 20088 22836 14608     . 14608 22
       4 "30/12/1999" 20453 22836 14608     . 14608 22
       4 "30/12/1999" 20819 22836 14608     . 14608 22
       4 "30/12/1999" 21184 22836 14608     . 14608 22
       4 "30/12/1999" 21549 22836 14608     . 14608 22
       4 "30/12/1999" 21914 22836 14608     . 14608 22
       4 "30/12/1999" 22280 22836 14608     . 14608 22
       5 "15/12/2000" 18992 22836 14959     . 14959 21
       5 "15/12/2000" 19358 22836 14959     . 14959 21
       5 "15/12/2000" 19723 22836 14959     . 14959 21
       5 "15/12/2000" 20088 22836 14959     . 14959 21
       5 "15/12/2000" 20453 22836 14959     . 14959 21
       5 "15/12/2000" 20819 22836 14959     . 14959 21
       5 "15/12/2000" 21184 22836 14959     . 14959 21
       5 "15/12/2000" 21549 22836 14959     . 14959 21
       5 "15/12/2000" 21914 22836 14959     . 14959 21
       5 "15/12/2000" 22280 22836 14959     . 14959 21
       6 "11/06/2002" 19358 22836 15502     . 15502 20
       6 "11/06/2002" 19723 22836 15502     . 15502 20
       6 "11/06/2002" 20088 22836 15502     . 15502 20
       6 "11/06/2002" 20453 22836 15502     . 15502 20
       6 "11/06/2002" 20819 22836 15502     . 15502 20
       6 "11/06/2002" 21184 22836 15502     . 15502 20
       6 "11/06/2002" 21549 22836 15502     . 15502 20
       6 "11/06/2002" 21914 22836 15502     . 15502 20
       6 "11/06/2002" 22280 22836 15502     . 15502 20
       6 "11/06/2002" 22645 22836 15502     . 15502 20
       7 "1962"       19358 22836     .   731   731 60
       7 "1962"       19723 22836     .   731   731 60
       7 "1962"       20088 22836     .   731   731 60
       7 "1962"       20453 22836     .   731   731 60
       7 "1962"       20819 22836     .   731   731 60
       7 "1962"       21184 22836     .   731   731 60
       7 "1962"       21549 22836     .   731   731 60
       7 "1962"       21914 22836     .   731   731 60
       7 "1962"       22280 22836     .   731   731 60
       7 "1962"       22645 22836     .   731   731 60
       8 "30/10/1980" 19358 22836  7608     .  7608 41
       8 "30/10/1980" 19723 22836  7608     .  7608 41
       8 "30/10/1980" 20088 22836  7608     .  7608 41
       8 "30/10/1980" 20453 22836  7608     .  7608 41
       8 "30/10/1980" 20819 22836  7608     .  7608 41
       8 "30/10/1980" 21184 22836  7608     .  7608 41
       8 "30/10/1980" 21549 22836  7608     .  7608 41
       8 "30/10/1980" 21914 22836  7608     .  7608 41
       8 "30/10/1980" 22280 22836  7608     .  7608 41
       8 "30/10/1980" 22645 22836  7608     .  7608 41
       9 "23/04/1934" 19083 22836 -9384     . -9384 88
       9 "23/04/1934" 19448 22836 -9384     . -9384 88
       9 "23/04/1934" 19813 22836 -9384     . -9384 88
       9 "23/04/1934" 20178 22836 -9384     . -9384 88
       9 "23/04/1934" 20544 22836 -9384     . -9384 88
       9 "23/04/1934" 20909 22836 -9384     . -9384 88
       9 "23/04/1934" 21274 22836 -9384     . -9384 88
       9 "23/04/1934" 21639 22836 -9384     . -9384 88
       9 "23/04/1934" 22005 22836 -9384     . -9384 88
       9 "23/04/1934" 22370 22836 -9384     . -9384 88
      10 "23/06/2003" 18992 22836 15879     . 15879 19
      10 "23/06/2003" 19358 22836 15879     . 15879 19
      10 "23/06/2003" 19723 22836 15879     . 15879 19
      10 "23/06/2003" 20088 22836 15879     . 15879 19
      10 "23/06/2003" 20453 22836 15879     . 15879 19
      10 "23/06/2003" 20819 22836 15879     . 15879 19
      10 "23/06/2003" 21184 22836 15879     . 15879 19
      10 "23/06/2003" 21549 22836 15879     . 15879 19
      10 "23/06/2003" 21914 22836 15879     . 15879 19
      10 "23/06/2003" 22280 22836 15879     . 15879 19
      end
      format %td eventdate
      format %td today_date
      format %td birth_date
      format %td birth_date1
      format %td birth_datee

      Comment


      • #4
        Using c(current_date) limits reproducibility as you or anybody else is likely to get some different answers for the same code run in the future. Better to write in some fixed date that is a convenient cut-off.

        Comment


        • #5
          Thank you for the suggestion Nick, I think in the dataex code, it is already fixed date 10/07/2022. I copy paste the question again with the fixed date. Do you have a suggestion for my problem?

          Best regards,


          You can see my code here.


          gen today_date=date("10jul2022","DMY")

          generate birth_date = date(DATE, "DMY")

          generate birth_date1 = date(DATE, "Y")

          generate birth_datee = cond(missing(birth_date), birth_date1, birth_date)

          format birth_datee %td

          gen age = int((today_date - birth_datee)/365.25)

          Do you think there is an easy way to do that?

          Best regards,

          Comment

          Working...
          X