Simulated data for logistic regression I used the code below to create the random variable x1 and binary variable y, and fit the regression with y and x1. My questions are:

*

*Why regression coefficient estimates are not close to 2 and 10 (the values I setup)?

*Why the warnning "did not converge"?

Thank you very much in advance for any thoughts!
n=1000
x1=rnorm(n)
xBeta=2+10*x1
p=1/(1+exp(-xBeta))
y=(p > 0.5)+0
dat = data.frame(y=y,x1=x1)
model <- glm(y ~ x1,family=binomial(link='logit'),data=dat)
summary(model)

Warning messages:
1: glm.fit: algorithm did not converge 
2: glm.fit: fitted probabilities numerically 0 or 1 occurred 

Call:
glm(formula = y ~ x1, family = binomial(link = "logit"), data = dat)

Coefficients:
                   Estimate      Std. Error z value Pr(>|z|)
(Intercept)  1209.197686004 11464.422053391 0.10547  0.91600
x1           5992.507564124 56805.078196891 0.10549  0.91599

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 1.3698653260741e+03  on 999  degrees of freedom
Residual deviance: 6.2933474676058e-05  on 998  degrees of freedom
AIC: 4.0000629334747

Number of Fisher Scoring iterations: 25


The answer to both questions is: because you are generating the response in the wrong way, because you are assuming the response to be fixed, conditionally on $x_i$.
Indeed, the binary logistic regression model can be written as
$$
Y_i \sim \text{Bernoulli}(p_i),
$$
$$
p_i = \frac{e^{\beta_0+\beta_1 x_i}}{1+e^{\beta_0+\beta_1 x_i}},\,\,i=1,\ldots,n.
$$
According to your assumptions, $\beta_0=2,\beta_1=10$, $x_i\sim \text{N}(0,1)$ iid and $n=1000$.
The correct way to generate the data from the model is thus
set.seed(1)
n=1000
x1=rnorm(n)
xBeta=2+10*x1
p=1/(1+exp(-xBeta))
y=rbinom(n,1,p)
dat = data.frame(y=y,x1=x1)
model <- glm(y ~ x1,family=binomial(link='logit'),data=dat)
summary(model)

