Announcement

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

  • Generating a dummy variabele when there is a decrease in productivity

    Dear all

    For my thesis I have to investigate a couple of things in regards to dismissals of a firm. I have panel data (34k firms; period of 10years) & I have to create a dummy that gives "1" in case the productivity has decreased when compared to last year. (& =0 if there is no decrease). Yet I can't find the commands to execute this. Anyone that might be able to help?

    Thanks in advance

  • #2
    Code:
    bysort firm (year): generate wanted = _n>1 & productivity<productivity[_n-1]
    This will give a 0 in the first year, and if a year is missing will compare the year to the previous non-missing year.

    It is the norm in the Statalist community to use our real given and surnames as our username, to promote professionalism and collegiality. Unfortunately, the Forum software does not permit you to edit your username. However, you can click on Contact Us in the lower right corner of this page and send a message to the system administrator requesting the correction. Your adherence to this norm will be appreciated and may increase the propensity of others to respond to your queries.

    Comment


    • #3
      My bad. Will contact for a correction. Thanks for your response! I keep getting this error:
      Click image for larger version

Name:	error.png
Views:	1
Size:	7.4 KB
ID:	1658256

      Comment


      • #4
        The first example failed because you discussed "productivity" without telling us the actual variable name. So I will use this as an excuse to give you a little more advice about Statalist.
        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.

        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.

        When asking for help with code, always show example data.
        With that said, the second example failed because in correcting the variable name you inserted a space between the second occurrence of the variable name and the left bracket. You apparently need
        Code:
        bysort firm (Tijd): generate wanted = _n>1 & Productiviteit < Productiviteit[_n-1]
        but check my spelling "Productiviteit" - I couldn't copy and paste what you used because you posted a picture of your Results window instead of text. So, some further advice about Statalist.
        Please review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. See especially sections 9-12 on how to best pose your question. It's particularly helpful to copy commands and output from your Stata Results window and paste them into your Statalist post using code delimiters [CODE] and [/CODE], and to use the dataex command to provide sample data, as described in section 12 of the FAQ.

        Comment


        • #5
          Thank you very much! Will definitely check the FAQ for next time

          Comment


          • #6
            Hi William
            I was just wondering... does this code know that when the data switches to another firm, that it does not need to look for the fact that there is a decrease in productivity?

            Kind regards
            Jordi

            Comment


            • #7
              The output of
              Code:
              help by
              or better yet, the full documentation in the PDF linked to from the top of this output, will explain how the by prefix works. The short answer is, yes, but you need to become familiar with the by prefix if you're using panel data.

              Comment


              • #8
                Alright, thank you!

                Comment


                • #9
                  Hi William

                  For my research I have this dependent variable "dummy dismissals" that indicates when there has been a dismissal of the workforce >= 10%. Currently I calculated this dummy with Excel before importing the Excel file to Stata. I've just noticed that in Stata the data of this variable "dummy dismissals" is not 100% correct. Solution: I have to create a dummy in Stata that gives the value "1" if there is a decrease >=10% of the workforce (year t), but the dismissals happen in the next year (t+1). I tried a code somewhat similar to the one in this post (about productivity), but that does not seem to work at all. Do you perhaps know this code? Thanks in advance.

                  EDIT: I don't need a dummy that indicates that there is a decrease >=10% of the workforce. I need: dismissals(t+1)/totalworkforce(t) & if this >=10%, then the "dummy dismissals" needs to be 1.
                  Last edited by Jordi Imbrechts; 08 Apr 2022, 07:02.

                  Comment


                  • #10
                    bysort ID (Year): generate Layoff= ( Afdankingenvoltijdseequivalen[_n]/ Totaalaantalwn[_n-1]) >=0.1
                    This does not seem to do the trick. It for example gives the value "1" to the first row (Year 2011: first year of panel data) when this is not possible because dismissals (n) is being compared to total workforce (n-1). Also when there are missing values for the variable "total workforce", it gives "1". (not what I want)

                    Comment


                    • #11
                      I need: dismissals(t+1)/totalworkforce(t) & if this >=10%, then the "dummy dismissals" needs to be 1.
                      Perhaps this is what you need.
                      Code:
                      bysort ID (Year): generate dummydismissals = dismissals[_n+1]/totalworkforce >=0.10 if !missing(totalworkforce[_n],dismissals[_n+1]) & Year[_n+1]==Year+1
                      so if either this years totalworkforce or next year's dummydismissals is missing, this year's dummydismissals will be missing, and it will also be missing if there is a gap in the data (the next observation is two or more years after this year's observation).

                      I tried a code somewhat similar to the one in this post (about productivity), but that does not seem to work at all.
                      I again refer you to the advice in post #4. You have the advantage of having looked at the data, run the code, and saw that it did not work in a way that you do not describe. But you decline to share the data, the code, and the details of how it did not work with us.

                      Comment


                      • #12
                        Thank you William.

                        Comment

                        Working...
                        X