Announcement

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

  • creating a dummy variable

    Dear All,

    I want to create four new dummy variables from the variable REGION2 which will NORTHEAST (REGION2==1) MIDWEST(REGION2==2) SOUTH (REGION2=3) WEST(REGION2=4)
    Click image for larger version

Name:	Region.png
Views:	1
Size:	6.2 KB
ID:	1679345


    I would appreciate if you can help me with the command

    With best regards,
    Upananda Pani

  • #2
    If you are doing this purely because you need the dummy variables for an estimation command (such as regress or logit), you do not actually need to create the dummy variables. You can use factor variable operators that will temporarily create the dummies needed for the command. See

    Code:
    help fvvarlist
    so e.g. in your regression of say y on x and region, you can just write

    Code:
    regress y x i.REGION2
    Last edited by Hemanshu Kumar; 26 Aug 2022, 02:16.

    Comment


    • #3
      You can create dummy variables from your factor variable with
      Code:
      tab REGION2, gen(REGION2_dummy)
      This way you get 4 new variables called REGION2_dummy1, REGION2_dummy2, REGION2_dummy3, REGION2_dummy4.

      Comment


      • #4
        Hi Mr. Juta K.,

        While I was trying to check your code, it is not working. Please see the following code I have used to create as per your suggesting.

        Code:
        tab REGION2, gen(REGION2_dummy1)
        tab REGION2, gen(REGION2_dummy2)
        tab REGION2, gen(REGION2_dummy3)
        tab REGION2, gen(REGION2_dummy4)
        
        rename REGION2_dummy1 northeast
        rename REGION2_dummy2 midwest
        rename REGION2_dummy3 south
        rename REGION2_dummy4 west

        Comment


        • #5
          I think this method is not proper as it is creating so many dummy variable not the way we want.

          Comment


          • #6
            Upananda Pani no, you just need to run the tab command once, and it will generate all four dummies for you. You are getting too many dummy variables (presumably, 16) because you are running the command four times. Just run the exact command that Juta gave you.

            Comment

            Working...
            X