Announcement

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

  • Generate Variables from the loop

    Hello everyone! I hope you are alright. I have a small problem. I would like my code to generate a single value from this loop (according to the num) and then append it to to the l_c variable, i.e. ideally I would have 27 observations in l_c variable. The value that I want to append is `m4', Thanks in advance!


    Code:
     
    gen l_c=.
    foreach num of numlist 70/97 {
      local m1 = `num'
      display  `m1'
      local m2= `num'-1
      local m3= m_tot_`m1' - m_tot_`m2'
      display `m3' //Total Change
      local m4= m_re_`m1' * ((n_re_`m1')/(n_kj_`m1'+n_cj_`m1'+n_fj_`m1'+n_re_`m1'))+( m_fj_`m1' *((n_fj_`m1')/(n_kj_`m1'+n_cj_`m1'+n_fj_`m1'+n_re_`m1')))-( m_bu_`m1' *((n_fj_`m1')/(n_kj_`m1'+n_cj_`m1'+n_fj_`m1'+n_re_`m1')))
      local m5= `m3'-`m4'
      display `m4' //Labour Change
      display `m5' //Job Change
      replace l_c = `m4'
      }

  • #2
    I guess

    * you have panel data held as variables, i.e. in wide format. or layout

    * you're getting confused between variables and locals. and between display and list.

    Please back up, and explain your data and your aim.

    Comment

    Working...
    X