16.2 Exercise: Control structures and loops

  1. Write an If-Argument for which y takes the value 10, if x is smaller than -50 or bigger than 50. If these conditions are not fulfilled y should take the value 0. Test this If-Argument by choosing different values for x.
  2. Start with a scalar a = 10 and write a loop that sequentially adds the numbers 2,4,6,8,10 to this scalar.
  3. Write a loop that replaces every second observation of the variable Fertility with missings (NA).