options crt; ? ODR (Orthogonal Distance Regression) set n = 10; smpl 1,n; random(seedin=4972) x; random e; ? measurement error in X (set up orthogonal to f) se = .2; ? weighted case -- weights can vary across observations random f; ? measurement error in Y sf = .3; random u; ? relationship error between true Y and X param a,2 b,1 su,.5; y = a + (x+e*se)*b + f*sf + u*su; ?print e x f y; olsq y c x; ? stores @fit for ols fitted values list(last=n,prefix=t) ts; trend t; dummy t; ? t1 = dummy for first obs, t2 for 2nd, etc. list(last=n,prefix=e) es; ? n nuisance parameters - the actual errors in x form(coefpref=e,param) eqe e ts; ? e = t1*e1 + t2*t2 + ... + tn*en; ? this selects the correct ei for each obs. frml odrw logl = -log(se) + lnorm(e/se) -log(sfu) + lnorm((y-(a + (x+e)*b))/sfu); frml sfu sqrt(sf*sf + su*su); ? std. deviation of composite residual eqsub odrw eqe sfu; ml(hiter=n,hcov=n) odrw; genr eqe; yfit = a + (x+e)*b; plot y,Y yfit,W @fit,O;