Announcement

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

  • Define a dummy variable

    I have a series for GINI index which takes a value in the interval between 0 and 1. (This series is panel data.) I want to assign a dummy variable for this GINI variable as defined by

    Click image for larger version

Name:	Screen Shot 2022-07-07 at 1.33.08 PM.png
Views:	2
Size:	13.2 KB
ID:	1672569


    For example, if Gini takes any number in the interval between 0 and 0.35, then the new defined dummy variable (dg) takes 0, and the like. How can I define this dummy variable dg in stata?

    I guess, I should use if command, but my stata command does not work.

  • #2
    I assume your gini index variable is called GINI

    Code:
    gen dg = (GINI == 2 | GINI == 3)
    should work

    Comment


    • #3
      Using Statalist is just like making wild mushroom risotto. If I asked you to make my favorite version of risotto, you'd likely need to know what the SPECIFIC ingredients (the data) are and the steps you do to make said dish (the recipe/code). So far you've given neither, you're asking us for help to make a dish, and you've not given the recipe (the code) or ingredients (the data).
      Precisely, you must give your dataset using dataex and your code that you've tried (formatted accordingly). No dataset, no code=no real assistance.

      Never say "does not work" when asking a question.

      Comment


      • #4
        Originally posted by Adam Sadi View Post
        I assume your gini index variable is called GINI

        Code:
        gen dg = (GINI == 2 | GINI == 3)
        should work
        -------

        I do not understand the underlying logic of this code. If Gini is any value between 0 and 0.35, then my defined dummy variable takes 0. If Gini is any value between 0.35 and 0.45, then my defined dummy variable takes 1. If Gini is any value between 0.45 and 0.55, then my defined dummy variable takes 2. And If Gini is any value above 0.55, then my defined dummy variable takes 3.

        Comment


        • #5
          We can only help you as much as you can demonstrate the problem. If you really want help with this, you'll show us your example dataset (as I've just asked for, using dataex) and the EXACT code you've tried.


          You see how when I ask questions I give a dataset and I give the code I've tried? This is what we must have from you. Sean Bilic

          Comment


          • #6
            Code:
            gen wanted = 3 if gini <= 1
            replace wanted = 2 if gini <= 0.55
            replace wanted = 1 if gini <=‘0.45
            replace wanted = 0 if gini <= 0.35
            but why not use the original values? Nothing magic happens at any of those thresholds.

            More complicated one-liners are possible.

            Comment

            Working...
            X