Announcement

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

  • Moving values to a column

    Hello,

    I am trying to create a single column for the variable (e.g. tinc) the values of which vary by birth cohort and group (10/40/50). Please see below the data example.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(year birthcohort group tinc189_10 tinc189_40 tinc189_50 tinc190_10 tinc190_40 tinc190_50 tinc191_10 tinc191_40 tinc191_50 tinc192_10 tinc192_40 tinc192_50 tinc193_10 tinc193_40 tinc193_50 tinc194_10 tinc194_40 tinc194_50)
    1968 189 50 82315896 18515090    3842.8         .         .         .          .          .         .          .          .          .          .          .          .          .          .          .
    1968 190 50        .        .         . 321978304 134224208   1649411          .          .         .          .          .          .          .          .          .          .          .          .
    1968 191 40        .        .         .         .         .         . 1037428672 1737417856 361478400          .          .          .          .          .          .          .          .          .
    1968 192 40        .        .         .         .         .         .          .          .         . 1365543808 2605007104 1423332992          .          .          .          .          .          .
    1968 193 50        .        .         .         .         .         .          .          .         .          .          .          . 1295371264 2750465792 1646105216          .          .          .
    1968 194 50        .        .         .         .         .         .          .          .         .          .          .          .          .          .          . 1076001280 2514751488 1644120320
    1968 195 40        .        .         .         .         .         .          .          .         .          .          .          .          .          .          .          .          .          .
    1968 196 40        .        .         .         .         .         .          .          .         .          .          .          .          .          .          .          .          .          .
    1969 188 50        .        .         .         .         .         .          .          .         .          .          .          .          .          .          .          .          .          .
    1969 189 50 65045464 22298824 110634.84         .         .         .          .          .         .          .          .          .          .          .          .          .          .          .
    1969 190 40        .        .         . 262564400 143402368 1477696.3          .          .         .          .          .          .          .          .          .          .          .          .
    1969 191 10        .        .         .         .         .         . 1163591808 1752346368 242811648          .          .          .          .          .          .          .          .          .
    1969 192 50        .        .         .         .         .         .          .          .         . 1628124288 2820037632 1530319872          .          .          .          .          .          .
    1969 193 40        .        .         .         .         .         .          .          .         .          .          .          . 1476368512 3.0468e+09 1849994240          .          .          .
    1969 194 50        .        .         .         .         .         .          .          .         .          .          .          .          .          .          . 1266009088 2762156800 1781505664
    1969 195 50        .        .         .         .         .         .          .          .         .          .          .          .          .          .          .          .          .          .
    1969 196 50        .        .         .         .         .         .          .          .         .          .          .          .          .          .          .          .          .          .
    1970 189 40 98906912 50724564   8839967         .         .         .          .          .         .          .          .          .          .          .          .          .          .          .
    1970 190 50        .        .         . 298547456 187856272  37247604          .          .         .          .          .          .          .          .          .          .          .          .
    1970 191 50        .        .         .         .         .         . 1122354944 1598025088 222942624          .          .          .          .          .          .          .          .          .
    1970 192 50        .        .         .         .         .         .          .          .         . 1654348288 3040544000 1621717888          .          .          .          .          .          .
    1970 193 50        .        .         .         .         .         .          .          .         .          .          .          . 1668577664 3478402560 2006760192          .          .          .
    1970 194 40        .        .         .         .         .         .          .          .         .          .          .          .          .          .          . 1246596608 2932580608 1934461184
    1970 195 50        .        .         .         .         .         .          .          .         .          .          .          .          .          .          .          .          .          .
    1970 196 50        .        .         .         .         .         .          .          .         .          .          .          .          .          .          .          .          .          .
    end
    I tried using the following code for the variables I have, but it omits some values.

    Code:
    gen tinc=.
    gen x=.
    gen y=.
    
    foreach var in tinc x y {
            foreach num of numlist 189/200{
                foreach x of numlist 10 40 50{
                        replace `var'=`var'`num'_`x' if birthcohort==`num' & group==`x'
        }
    }
    }
    I would appreciate any suggestion!

  • #2
    You can loop along:

    Code:
    egen tinc40= rowmax(tinc*40)

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      You can loop along:

      Code:
      egen tinc40= rowmax(tinc*40)
      Great, thanks a lot!

      Comment

      Working...
      X