A new variable as a sum of other variables

A new variable as a sum of other variables

by Isaac -
Number of replies: 2

I thought this would be easy, but it's proving the opposite.

I am trying to generate a new variable that is the sum of several other variables. What I found is that this should be easy:

Gen newvar = v1 + v2 + ....

However, it's not working for me. Initially, I thought it was because my v1 - v3 weren't clean (had some mistyped letters and whatnot in there), so I cleaned them. So, now they are entirely numeric.

Nonethtless:

gen total_drinks_week = how_many_wine_clean + how_many_beer_clean + how_many_liquor_clean

type mismatch r(109);

 

IDEAS?

Ziggy

 

In reply to Isaac

Re: A new variable as a sum of other variables

by Isaac -

I think I'm on to something....

I tabulated how_many_beer_clean and found that the numeric ordering on the side is not chronological. Then just to trouble shoot things, I tried to dotplot the same variable, and it said "string variable not allowed." So, for some reason STATA still thinks this is a string variable, even though all the fields are numeric - and I think that the non-chronologic ordering in the tabular display may be related to this.....

how_many_be |
   er_clean |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      2,151       57.71       57.71
          1 |        624       16.74       74.46
         10 |         37        0.99       75.45
         12 |         18        0.48       75.93
         13 |          1        0.03       75.96
         14 |         14        0.38       76.33
         15 |          5        0.13       76.47
         16 |          3        0.08       76.55
         18 |          1        0.03       76.58
          2 |        332        8.91       85.48
         20 |         14        0.38       85.86
         21 |          1        0.03       85.89
         22 |          1        0.03       85.91
         24 |          4        0.11       86.02
         28 |          1        0.03       86.05
          3 |        185        4.96       91.01
         30 |          6        0.16       91.17
         35 |          1        0.03       91.20
         36 |          2        0.05       91.25
          4 |        118        3.17       94.42
          5 |         76        2.04       96.46
         56 |          1        0.03       96.49
          6 |         62        1.66       98.15
          7 |         40        1.07       99.22
          8 |         25        0.67       99.89
         85 |          1        0.03       99.92
          9 |          3        0.08      100.00
------------+-----------------------------------
      Total |      3,727      100.00

In reply to Isaac

Re: A new variable as a sum of other variables

by Chloe Atreya -

Gen newvar = v1 + v2 + ....  should work, provided that the variables are numeric

I think that you are onto something with the string variable error, although numbers in table definitely don't need to be chronologic. 

Is it possible that there is a sneaky "O" "0" difference or hidden punctuation that is causing the variable to be classified as string?