Announcement

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

  • Creating variable from multiple existing variables

    Dear All,

    I am trying to create a new variable based on values from existing variables. Below is a snapshot of my dataset. I have variables X1-X8, and i'm trying to create variable X, which takes the value GR 2007 in the first row, GR 2008 in the second row, etc. There are no two values on the same row.

    I tried gen X=X1 | X2 | X3 ..., but then X takes only the value 1. How do i go about it?

    Thanks very much for your help, much appreciated!
    Magda


    country year X1 X2 X3 X4 X5 X6 X7 X8 X
    GR 2007 1.17
    GR 2008 0.70
    GR 2009 1.06
    GR 2010 0.50
    GR 2011 0.26
    GR 2012 0.45
    GR 2013 0.80
    GR 2014 0.47
    IE 2007 1.07
    IE 2008 0.78
    IE 2009 0.50
    IE 2010 0.36
    IE 2011 0.23
    IE 2012 0.20
    IE 2013 0.15
    IE 2014 0.36
    IT 2007 5.03
    IT 2008 4.73
    IT 2009 5.42
    IT 2010 5.04
    IT 2011 5.22
    IT 2012 4.72
    IT 2013 4.51
    IT 2014 4.42

  • #2
    See -rowfirst- within -help egen-:
    Code:
    egen x = rowfirst(x1-x8)

    Comment


    • #3
      this would have been much easier if you had, as requested in the FAQ, provided a -dataex- example; please see the FAQ; here is untested code which I think does what I think you want; note that I have added a "/" but you might want something else, or even nothing, instead;
      Code:
      egen X=concat(country year), p(/)
      note that there appear to be no missing values in your example and thus nothing to take care of; see
      Code:
      help egen
      and look at the "concat" function

      also note that your syntax is wrong anyway with more than one syntax mistake

      Comment


      • #4
        Thank you so much for the prompt reply, it worked! (i tried the egen rowfirst command).

        I will use -dataex- next time, many thanks for the tip.

        Comment

        Working...
        X