Announcement

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

  • Help with merging variables

    Good afternoon,

    I am new here and would greatly appreciate some help. I have two variables about weight in the same dataset, one with integer values and the other with decimal values. I would like to create a variable with the exact measurement. How can I do it?

    Any help is very appreciated.

  • #2
    It's hard to tell exactly what you want from your description. Please read the FAQ and the good advice contained there on using dataex to present example data. Example data, whether it is from your real data set or fake data you have created to illustrate your problem, allows us to help you construct code that will work with your specific situation.

    In this case since you do not describe your data we are forced to kind of guess at what you have and what you want. My guess from your description is that you want a variable that is the sum of your two existing weight variables. In that case you could try

    Code:
    gen want_wgt=weight1+weight2

    Comment


    • #3
      Thanks Sarah for your recommendation.

      It's a dataset whose two variables (integer_weight and decimal_weight) have 3 847 observations. To illustrate my problem I put an example with fake data.
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input int integer byte decimal float new_var
      48 3 48.3
      56 6 56.6
      53 2 53.2
      49 1 49.1
      52 8 52.8
      end
      I would like create a new variable (as in the example) from the previous two (integer and decimal).

      Comment


      • #4
        Hi Jairo, and welcome to Statalist!

        I answered a similar question here

        But using your data:

        Code:
        gen combined = integer + (decimal / 10)
        list, noobs
        
        . list, noobs
        
          +----------------------------------------+
          | integer   decimal   new_var   combined |
          |----------------------------------------|
          |      48         3      48.3       48.3 |
          |      56         6      56.6       56.6 |
          |      53         2      53.2       53.2 |
          |      49         1      49.1       49.1 |
          |      52         8      52.8       52.8 |
          +----------------------------------------+
        Hope that helps!

        Comment


        • #5
          Oh I find it, Thanks a lot David!

          Comment

          Working...
          X