Announcement

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

  • Regression With and Without One Observation

    Hello everyone,

    Currently I am working on my thesis about Germany. Berlin is of course the capital. I want to do some regressions with and without Berlin, thus temporarily drop the observation of Berlin.
    However, I need it in a later stage again. Is there a possibility of running a regression excluding this observation and directly afterwards include it again for another regression?

    Or is it better to make a dummy out of this. Then gen Berlin = observation326 --> then 0=without and 1=with.

    I prefer the option without creating a new variable.

    Thanks in advance.

    Jantje

  • #2
    So, if we assume that the Berlin observation is identified by a string variable called city, then just add -if city != "Berlin"- to your analysis commands. If there are a large number of commands, making that inconvenient you can do this:

    Code:
    // ANALYSES WITH BERLIN INCLUDED HERE
    
    preserve
    drop if city == "Berlin"
    // SAME ANALYSIS COMMANDS AS BEFORE GO HERE
    restore
    // ALL THE DATA ARE NOW BACK

    Comment


    • #3
      Thank you very much. Didn't know about the probably basic preserve restore actions.
      I was looking from something with "ignore in 326".
      Just dropped the observation and restored it and it worked of course.

      Comment


      • #4
        Jantje:
        Clyde's code is obviously smart and effective, but, as a matter of personal taste, I would strongly favour creating a new variable (I made some mishaps in the past and deleted observations permanently):
        Code:
        gen flag=1 if city=="Berlin"
        replace flag=0 if flag==.
        reg depvar indepvars if flag!=1
        Whenever you want to include Berlin into your regression, just type:
        Code:
        reg depvar indepvars
        A simpler approach would be:
        Code:
        reg depvar indepvars if city!="Berlin"
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          The advantage of creating a dummy for Berlin is that is allows you to test whether Berlin is really an outlier.

          Comment

          Working...
          X