Project

General

Profile

Actions

Support #907

open

Error message (invalid 'and') while trying to loop

Added by OLAYIWOLA OLADIRAN almost 7 years ago. Updated almost 7 years ago.

Status:
Resolved
Priority:
Urgent
Category:
-
Start date:
01/29/2018
% Done:

100%


Description

Hi,

I am trying to merge BHPS to the UKLS data. Using the command below, by the time I get to foreach (looping), it gives me an error message: _""""""invalid 'and'
r(198);"""""
What am I doing wrong?

capture mkdir M:\example9data
global dir3 "M:\example9data\"
log using $dir3\Example9.log, replace
foreach w in a b c d e f g h i j {
use pid `w'hid `w'pno `w'hlghq1 `w'jbstat `w'xrwght `w'sex ///
using $dir2/`w'indresp, clear
renpfix `w'
gen wave = strpos("abcdefghijklmnopqr","`w'")
recode jbstat (5=6) (6=7) (7=8) (8=5) if wave==1
// The coding frame of ajbstat needs to be aligned with that of other
// waves. Best to do this before appending other waves as labels get
// overwritten.
lab var wave "wave of BHPS interview"
sort pid wave
save $dir3/ind_junk`w', replace
}
foreach w in k l m n o p q r {
use pid `w'hid `w'pno `w'hlghq1 `w'jbstat `w'xrwght `w'xrwtuk1 `w'sex ///
using $dir2/`w'indresp, clear
renpfix `w'
capture rename id pid
// this line of command is only needed in wave 16 (p) so was not needed
// in the previous loop
gen wave = strpos("abcdefghijklmnopqr","`w'")
lab var wave "wave of BHPS interview"
sort pid wave
save $dir3/ind_junk`w', replace
}


Files

merging error.JPG (42.8 KB) merging error.JPG OLAYIWOLA OLADIRAN, 01/30/2018 01:57 PM
Actions

Also available in: Atom PDF