Announcement

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

  • problem creating index variable

    Am trying to create an index variable (var4) by adding three component variables (var1, var2, var3). Vars 1 and 2 range from 0-100 and var3 is a 0/1 variable. (The describe command identifies the storage type of vars 1 and 2 as float and vars3 as byte.) So I’m trying to use the command gen var4=var1+var2+var3 which will run. The problem is if you list var4 to check the addition it just adds var1 and var2 and excludes var3. Thought this might be because of incompatible variable formats and changed var3 from byte to float but this didn’t work. Thoughts? Thanks, RB

  • #2
    that should work (if none of the variables are missing); please show us a few cases (copy-and-paste between CODE block delimiters please - see the FAQ if this is not clear)

    another options would be to use the egen command with the rowtotal function; see "h egen"

    Comment


    • #3
      rbac(please, read FAQ #6 about how to re-register wit real full names, as preferred on this forum. Thanks).
      Provided that your variables show no missing values, I would try:
      Code:
      egen index=rowtotal(var1 var2 var3)
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        actually, if any of the variables are missing, then egen with rowtotal will treat that as though it is 0 (but there is an option to make the total missing if all variables are missing)

        Comment


        • #5
          The egen did the same thing. Am thinking it is a missing values problem. Var1 has 18 of 1169 missing and var2 has 21 of 1169 missing. Sent email to re-set username.
          Robert Biggert

          Comment


          • #6
            However var1 + var2 + var3 as argument to generate would return missing if any of those were missing. It would not "exclude var3" as first reported.

            We need to see enough of your data and code to understand what is going on.

            (A quite different point is that adding values ranging 0-1 to variables ranging 0-100 will not usually be the right thing to do in index creation!)

            Comment


            • #7
              Used the missing option with egen and that fixed it. Thanks, Robert Biggert

              Comment

              Working...
              X