Announcement

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

  • Help with generate dummy

    Click image for larger version

Name:	Bild.png
Views:	3
Size:	75.7 KB
ID:	1490642


    Hi!
    This is a part of my data. I have 24 countries (land) and I want to make two dummy's for aviation transport for Sweden - one that makes Swedish Total passengers aviation =1 and then the other Swedish Total passengers travel by railway=0. We want to exclude there other lands so we only look at Sweden.

    An illustration of what I want to do:
    Click image for larger version

Name:	bild 2.png
Views:	1
Size:	7.8 KB
ID:	1490643



    How can I do that?

    Thanks in advanced
    David
    Attached Files

  • #2
    Generally speaking, you can generate a binary variable like this: gen newvar = oldvar == #.

    If you have a string variable, such as "land", you may add the value under quotes.

    That being said, I fail to understand how your query, since aviation is a continuous variable and you didn't inform a cut off value.
    Best regards,

    Marcos

    Comment


    • #3
      Click image for larger version

Name:	tabell.png
Views:	1
Size:	43.9 KB
ID:	1490753


      Thank you for replying!

      I will try to formulate my question in another way. So what I want to do is that I want to generate a dummy for Sweden aviation =1 and Sweden railway = 0. In the tabel above I describe how I want it (Look at E). But instead of doing it manually in a different excel document I would like to do it directly from the data I posted in the first post in Stata.

      David

      Comment


      • #4
        You didn't show this variable in #1. Assuming it is a string, you may type:

        Code:
        gen mydummy = .
        replace my dummy = 1 if transport == "Aviation" & Land == "Sweden"
        replace mydummy = 0 if transport = "railway" & Land == "Sweden"
        For a better approach, please read the FAQ. There you'll find how to properly share data/command/output.
        Best regards,

        Marcos

        Comment


        • #5
          Thank you so much! This helped me

          Comment


          • #6
            There is a typo in #4, line 2: it should be mydummy, not ‘my dummy’.

            Thank you for informing your query reached a satisfactory closure.
            Best regards,

            Marcos

            Comment

            Working...
            X