Announcement

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

  • Generata new variable withouth if condition in stata 17

    Hello there,

    I am using STATA 17. I have this code I have tu run on a shared panel dataset at the firm-level. ideally I have to generate a variable that contain the number of observation based on a few conditions.


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(deleg mtarget reloc)
    0 0 0
    0 0 0
    0 0 0
    0 0 0
    0 0 0
    end
    where del, mtarget and reloc are three dummies taking values 0 and 1 if the firm has been touched by a public provision, has been bought or relocated respectively. It is not that important the meaning fo the vars per se, I just would like to know why my team is able to run this code below in multiple occasions and with several modifications, while I with stata 17 I can't and I can't seem to figure out the reason either.

    Code:
    #delimit;
    use ${exit}firmexit_4plus4.dta, clear; ///THIS RUNS
    
    
    /* use for analysis only if single-establishment, not in a merger and no relocation */
    gen inpanel=(deleg==0 & mtarget==0 & reloc==0); //// THIS DOES NOT
    label var inpanel "use obs for analysis";
    Thanks for anyone who might help,
    Best
    DR

  • #2
    "Does not run" can mean many things: it gives an error message (which one?), it does not give you the results you expect (what results does it give you? and what results do you expect?), Stata crashes, something else. So can you tell us exactly "does not run" means in your case?
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      you're right,
      here you go:


      . gen inpanel=(deleg==0 & mtarget==0 & reloc==0);
      unknown function ()

      the error I get is unknown function, which is weird since this cose has already been used and tested and gives expected results to others that have used it in my team.

      Best,
      Dalila

      Comment


      • #4
        UPDATE:

        If I take out the delimiter ";" then the code does work correctly and gives the expected results. But I wonder why this conflict betweer setting the delimiter at the beginnning of the code and then having issues for each line (like error uknown) I try to execture.

        Comment


        • #5
          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input float(deleg mtarget reloc)
          0 0 0
          0 0 0
          0 0 0
          0 0 0
          0 0 0
          end
          
          #delimit;
          gen inpanel=(deleg==0 & mtarget==0 & reloc==0); // THIS DOES NOT
          label var inpanel "use obs for analysis";
          This runs on my Stata 17 without problem.

          I do get this error message when I run this line by line. The problem is that #delimit; says that commands end with a ; but only for as long as that do file runs. So if you execute just the line #delimit; it sets the delimiter to ; but only for as long as it is running, and than sets it back again to the carriage return. Then the next line you try to execute gen inpanel=(deleg==0 & mtarget==0 & reloc==0); notice the ; at the end, except that the "end of command symbol" is set back again to carriage return rather than ; so Stata does not understand what you are doing. The easiest solution is to just remove the line #delimit; and remove all the ; . Alternatively, just run the do file in one go, and not line by line.
          ---------------------------------
          Maarten L. Buis
          University of Konstanz
          Department of history and sociology
          box 40
          78457 Konstanz
          Germany
          http://www.maartenbuis.nl
          ---------------------------------

          Comment


          • #6
            I actually never used the #delimit command, I got the gist by intuition but many thanks for such an explanation!

            Best,
            Dalila

            Comment

            Working...
            X