Announcement

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

  • Create a change variable between years

    Hello everyone,

    I have a panel data set containing unique company identifiers, fiscal year end and total assets.

    I'm looking to create a change variable indicating the change of total assets from year t-1 to year t.

    an extract of the data looks like this:
    isin_identifier total_assets fiscal_year_end
    "DE0003304002" 564254 Dec 31 05
    "DE0003304002" 621866 Dec 31 06
    "DE0003304002" 967840 Dec 31 07
    "DE0003304002" 1044262 Dec 31 08
    "DE0003304101" 232795 Oct 31 06
    "DE0003304101" 270419 Oct 31 07
    "DE0003304101" 296583 Oct 31 08
    "DE0003304101" 290596 Oct 31 09
    Code:

    egen panelid = group(isin)
    xtset panelid fye
    bysort panelid fye:gen chTA = total_assets-L.total_assets

    stata ouput shows: "1,034 missing values generated",which failed the task.

    Does anyone has a suggestion?

    Thank you in advance
    Last edited by Lang Ding; 26 May 2017, 14:11.

  • #2
    So, the problem is that you have a daily date but the lag you want is a year. Because your date is daily, Stata thinks the lag you want is the value from the preceding day. Of course, you don't actually have values for the preceding days, so you get missing values for results.

    Here's a different approach that works with your example data:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str14 isin_identifier long total_assets float fiscal_year_end
    `""DE0003304002""'  564254 16801
    `""DE0003304002""'  621866 17166
    `""DE0003304002""'  967840 17531
    `""DE0003304002""' 1044262 17897
    `""DE0003304101""'  232795 17105
    `""DE0003304101""'  270419 17470
    `""DE0003304101""'  296583 17836
    `""DE0003304101""'  290596 18201
    end
    format %td fiscal_year_end
    
    gen fy = year(fiscal_year_end)
    egen panelid = group(isin_identifier)
    xtset panelid fy, yearly
    
    gen chTA = total_assets-L.total_assets
    Note, by the way, that I do not need a by: prefix on the final command. When the data are -xtset-, expressions involving time series operators such as L are automatically evaluated within panels.

    In the future, please post example data using the -dataex- command, as I have done here. HTML tables can be difficult to wrestle into Stata; they often require considerable ad hoc editing to make them usable. When you use -dataex-, you enable those who want to help you to use a simple copy/paste operation to create a completely faithful replica of the data you are showing that incorporates all of the necessary details of format, storage types, labeling, and the like. Run -ssc install dataex- to get the -dataex- command, and then run -help dataex- to read the simple instructions for using it.

    Comment


    • #3
      Hi Clyde,

      Thanks for insightful solution, now it works.

      Regarding the the reminder, I have read the instruction given by Mr. Picard from the following link:
      http://www.statalist.org/forums/foru...-for-statalist
      while in application, it shows in stata a result that I cannot use for posting.

      e.g. when I put in "dataex fye" with the intention to display the "fiscal_year_end" information, the following displays:

      [CODE]
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input int fye
      16801
      17166
      17531
      17897
      17105
      17470

      Again many thanks for the neat answer.

      Comment

      Working...
      X