Announcement

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

  • Help: Generating a new variable on a subsample

    Hello!

    I am a beginner in Stata.

    My problem:
    I have a selection of countries in my dataset and I want to do a regression on only a subset of these countries.
    In my case, my data contains the countries of the world, but I only want my regression to cover the region of North Africa.
    But I am unable to figure out the exact command for this.

    So basically I want to do something like this:

    regress Y-variable X-variable if country_name == "Tunisia", "Egypt", "Morocco", "Tunisia", "Algeria", "Libya", "Sudan"

    What am I missing here?



    //Thank you

  • #2
    Code:
    regress Yvariable Xvariable if inlist(country_name, "Tunisia", "Egypt", "Morocco", "Algeria", "Libya", "Sudan")

    Comment


    • #3
      Originally posted by Nick Cox View Post
      Code:
      regress Yvariable Xvariable if inlist(country_name, "Tunisia", "Egypt", "Morocco", "Algeria", "Libya", "Sudan")
      Thank you.

      Another quick question. I want to only include years from 2000 until today in the regression.
      Thus, I have done the following:

      gen current_era = year if year >= 2000

      How do I perform the regression using only this time period?
      I.e. so that the regression is applied to cases that follow the current_era variable.



      Thank you for the help.

      Comment


      • #4
        You can just regress using the new variable. But you don't need a new variable


        Code:
        regress ... if year >= 2000 ...
        should work where ... is everything else you want to say.

        Detail: >= 2000 includes missing values too, so watch out.

        Comment

        Working...
        X