Is there a R command for testing the difference in coefficients of two linear regression​s? I am looking for a R command to test the difference of two linear regressoon betas. Lets say I have data $x_1, x_2...x_{n＋1}$.
$\beta_1$ is obtained from regressing $x_1$ to $x_n$ onto $1$ to $n$.
$\beta_2$ is obtained from regressing $x_2$ to $x_{n＋1}$ onto $1$ to $n$.
Is there a way in R to test whether $\beta_1$ and $\beta_2$ are statistically different?
Edit:
Here is a clearer problem statement:
I changed the notation for data from $x$ to $z$...
That's it. Should be very clear now... Thanks!
Data observations: $z_1, z_2, ..., z_{n+1}$
y1 = z_1,z_2,.........  z_n 
y2 = z_2, z_3,......... z_{n+1}

x1 = 1, ..., n
x2 = 1, ..., n

y1 = A1+ x1 * B1 + epsilon_1
y2 = A2 + x2 * B2 + epsilon_2

H0: B1 and B2 are statistically significally different...
 A: You can stack the data so that you have $x_1 ... x_n$ followed by $x_2 ... x_{n+1}$ in one column, then the next column would have $1 ... n$ repeated twice, then a third column would have $0$'s coresponding to the 1st group and $1$'s for the second group.  Now do the regression including an interaction between the $1 ... n$ and the $0/1$ group variable.  The slope for the interaction represents the difference between the 2 slopes you are interested in, testing the interaction will test if the slopes are different.  However, the standard regression assumptions may not hold here (your data certainly is not independent), so you should do some type of simulation under the null hypothesis to determine the critical region to use to determine significance.
Here is some example R code:
y1 <- anscombe$y1[order(anscombe$x1)]
y2 <- anscombe$y2[order(anscombe$x2)]


df1 <- data.frame( y=c(y1[-11], y1[-1]), x=rep(1:10, 2), g=rep(0:1, each=10))
df2 <- data.frame( y=c(y2[-11], y2[-1]), x=rep(1:10, 2), g=rep(0:1, each=10))

fit1 <- lm( y ~ x*g, data=df1 )
fit2 <- lm( y ~ x*g, data=df2 )

tmpfun <- function(n, beta, sigma) {
    x <- 1:n
    y <- beta*x + rnorm(n,0,sigma)
    df <- data.frame( y=c(y[-n],y[-1]), x=rep(seq(to=n-1), 2), 
        g=rep(0:1, each=n-1) )
    fit <- lm( y~x*g, data=df )
    coef(fit)[4]
}

tmpfit <- lm(y1 ~ seq_along(y1))
out1 <- replicate(1000, tmpfun(11, coef(tmpfit)[2], summary(tmpfit)$sigma) )
hist(out1)
abline( v=quantile(out1, c(0.025, 0.975)), col='red')
abline( v=coef(fit1)[4], col='blue' )

tmpfit <- lm(y2 ~ seq_along(y1))
out2 <- replicate(1000, tmpfun(11, coef(tmpfit)[2], summary(tmpfit)$sigma) )
hist(out2)
abline( v=quantile(out2, c(0.025, 0.975)), col='red')
abline( v=coef(fit2)[4], col='blue' )

If you tell us more about what you are trying to accomplish we may be able to suggest better methods.
A: Are you doing something like:
set.seed(1)

x1<-rnorm(100,1) 
x2<-rnorm(100,mean(x1))
y<-rnorm(100, mean(x1+x2)+rnorm(100))

fit1<-lm(y~x1, data)
fit2<-lm(x1~x2, data)

If so, you might be able to get away with:
d<-coef(fit1)[2] - coef(fit2)[2] 

coef(fit)[2] is the second coefficient in the model, i.e. the beta

var1<-summary(fit1)$coef[4]^2 

This is the fourth coefficient in the summary, or the se of beta1
var2<-summary(fit2)$coef[4]^2


ztest<- d / sqrt(var1+var2)

1-pnorm(ztest)

       x1 
0.5918211 

this was my answer, so I would say there is no difference, but beta1 was -.11 and beta 2 was .-07, so they're pretty similar.
