Announcement

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

  • Generating a Dummy Variable Based on Several Conditions

    Hello.

    I am working on an empirical project in accounting and need help in generating a dummy variable.

    My point of reference is an article published in the Accounting Review (Cheng, 2004). The author states on page 310 how he obtains the variable "myopia." It equals 1 if a firm faces a small earnings decline or a small loss in a given year, and 0 otherwise. Specifically, firm i in year t faces a small earnings decline if it satisfies two conditions: (1) pretax incomeit + R&D expendituresit < pretax incomeit-1 + R&D expendituresit-1, and (2) pretax incomeit + R&D expendituresit > pretax incomeit-1. Firm i in year t has a small loss if -1 percent ≤ pretax incomeit / market value of equityit-1 < 0.

    I have panel data for firms over years, as the author does, and have also all the variables that are necessary to generate the variable "myopia", namely pretax income, R&D expenditures, their lags, and the lag of market value of equity. I face some difficulty in specifying the code for generating the variable in Stata 17 and would be grateful for your help.

  • #2
    Code:
    xtset firm year
    
    gen byte small_earnings_decline = pretax_income + r_d_expenditures ///
        < L1.pretax_income + L1.r_d_expenditures ///
        if !missing(L1.pretax_income, L1.r_d_expenditures)
        
    gen byte small_loss = inrange(pretax_income/L1.market_value_of_equity, -0.01, 0)
    
    gen byte myopia = small_loss & small_earnings_decline ///
        if !missing(small_earnings_decline)
    Note: As no example data was given, this code is written for an imaginary data set that may or may not resemble the structure and nature of your data. If my imaginations are easily translatable to your data by the substitution of your variable names for mine, then this code should do what you ask. But, also because of lack of example data, this code is untested. Therefore it may contain typos or other errors I could not discover.

    In the future, when asking for help with code, always show example data. And the helpful way to show example data is with the -dataex- command. 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- to 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.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.
    Last edited by Clyde Schechter; 08 Jun 2022, 15:44. Reason: Correct error in code.

    Comment


    • #3
      Thank you very much for your reply, dear Professor Schechter.

      I will try to run this code on my dataset and post an update with the example data if it does not work.

      Also if it does work, I will post an update to thank you for your support because having this variable is critical for further analyses in the project.

      Comment


      • #4
        Originally posted by Clyde Schechter View Post
        Code:
        xtset firm year
        
        gen byte small_earnings_decline = pretax_income + r_d_expenditures ///
        < L1.pretax_income + L1.r_d_expenditures ///
        if !missing(L1.pretax_income, L1.r_d_expenditures)
        
        gen byte small_loss = inrange(pretax_income/L1.market_value_of_equity, -0.01, 0)
        
        gen byte myopia = small_loss & small_earnings_decline ///
        if !missing(small_earnings_decline)

        Dear Professor Schechter,

        This code works for my dataset, and I was able to generate the variable.
        Thank you very much for your support.

        Regards,
        Gayane

        Comment

        Working...
        X