Announcement

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

  • foreach help - factor variables and time-series operators not allowed - merge help

    Hello,

    I am trying to merge two datasets (UK understanding society survey and a specific accessibility related dataset). The accessibility related dataset basically adds accessibility related info to the UK understanding society survey data, so they share personal identifiers etc. The user guide for the accessibility related file explains that to merge this one with the broader survey data I should infput:

    foreach x in a b c {

    use a_indall.dta, replace

    renpfix `x'a_indall.dta, replace

    gen wave= strpos(abc,`x’)

    save `x'junk, replace

    }

    foreach x in a b {

    append using `x'junk

    }

    merge 1:1 pidp wave using ukhls_accessibility_w1tow3_protect.dta



    I have tried but I get this error:

    factor variables and time-series operators not allowed
    r(101);


    Any idea why?

    Thanks!

  • #2
    My guess is that your purpose requires something like

    Code:
    foreach x in a b c {
        use a_indall.dta, replace
        renpfix `x'a_indall.dta, replace
    
        * !!! this line is different 
        gen wave = strpos("abc", "`x')
        save `x'junk, replace
    }
    
    foreach x in a b {
        append using `x'junk
    
    }
    
    merge 1:1 pidp wave using ukhls_accessibility_w1tow3_protect.dta
    That said, this looks like an attempt to do by file choreography something that might be easier with reshape long.

    Comment

    Working...
    X