Announcement

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

  • Combined new variable: code MV from other variables

    I would like to create a variable in which I code 1 if a certain threshold in several other indicators is met. 0 only if the threshold is not met in any of the variables. In my case, I'm trying to assess the "objective" interest of a country in migration if the share of immigrants OR the share of emigrants OR the share of remittances/GDP is beyond my thresholds.

    I did the following:

    . gen miginterest1=1 if immi_share>=0.15
    . replace miginterest1=1 if emi_share>=0.15
    . replace miginterest1=1 if remit_share>=15

    *Since I needed the rows that didn't meet my threshold to be coded as 0 I did:
    . mvencode miginterest1, mv(0)

    * the problem is that this also codes countries where there is missing information as 0, which it should't. I tried to recode, if and replace if but it didn't work. It's probably a straightforward syntax issue but any help would be appreciated! Thanks!

  • #2
    the problem is that this also codes countries where there is missing information as 0, which it should't
    There are three variables, and you haven't said which combinations of missingness among them are to be treated how under what circumstances with regard to the others. How should missing information be handled? Be very specific.


    Comment


    • #3
      thanks for pointing this out. For now, we can say if there is a MV in any of the three variables it should be coded as MV (I can always recode it later). Any suggestions are much appreciated!

      Comment


      • #4
        Code:
        gen wanted = max((immi_share >= 0.15), (emmi_share >= 0.15), (remit_share >= 15))  if !missing(immi_share, emmi_share, remit_share)
        insofar as

        max(1 or 0, 1 or 0, 1 or 0) will be 1 if any argument is 1.

        Last edited by Nick Cox; 28 Mar 2022, 09:55.

        Comment


        • #5
          Thanks! Much appreciated!

          Comment

          Working...
          X