Announcement

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

  • Using multiple 'if' commands

    Hi all,

    I'm currently attempting to ask Stata to code a variable as '1' if it meets several criteria, and 0 if it doesn't. Here's the code below, which may make more sense than my explanation:

    "gen radicalright=0

    replace radicalright=1 if (stack==3 country==1)"

    Stata gives me the following error message when I run this:
    "3country invalid name"

    Any idea where I'm going wrong?


    Many thanks for your help,

    Tom

  • #2
    Run -help operators-.
    You should:

    1. Read the FAQ carefully.

    2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

    3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

    4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

    Comment


    • #3
      Robert is spot on. You must learn about &, |, etc. to make progress here.

      As the correct word definition is not clear, I guess at something like

      Code:
      gen radicalright= stack==3 & country==1
      (What you refer to are if qualifiers; the if command is something different. Often, as above, you don't need either.

      Comment


      • #4
        1

        Comment

        Working...
        X