Estimates the second of a sorting model

second_stage(s1.results, data, endog = NULL, instr = NULL)

Arguments

s1.results

Indicates the (maxLik) object estimation results of the first stage of the sorting model

data

Dataset to be used

endog

Indicates the endogenous variable(s) to be instrumented (from the dataset in parentheses)

instr

indicates the intrument(s) for the endogenous variable

Value

An estimation object

Details

This function estimates an OLS or an instrument variable. if an instrument variable procedure is needed both the instrument and the endogenous variables should be given

Examples

data <- municipality s1.results <- first_stage(code_name = "mun_code", X_names = c("lnprice","kindergardens_1km","p_mig_west","nature","monuments","cafes_1km"), Z_names = c("income","double_earner_hh","hh_kids","age", "migskill"), data = data, print_detail = 1)
#> -------------- #> successive function values within tolerance limit #> 13 iterations #> estimate: -0.5165651 -2.657561 -2.420705 -3.268584 -2.808338 -3.759156 -1.802347 -1.973176 -3.081623 -2.945921 -5.047281 -2.632009 -1.924907 0.6414166 -1.673695 -3.226506 -2.754643 -2.31913 -1.806289 -1.485187 -2.556821 -0.459179 0.9716554 -4.94152 -4.294334 -2.106439 -3.62121 -3.741176 -1.913509 -2.368222 -2.91929 -2.524537 -0.5003825 -3.567914 -0.8614097 -2.499268 -2.568059 -1.241397 -2.247542 -3.512908 -3.546684 -4.108796 -2.516137 -3.583525 -3.79585 -1.205857 -3.642069 -2.655842 -1.543215 -2.794182 -2.722002 -4.293146 -0.1461192 -2.854304 -1.448037 -1.868635 -3.200991 -3.074543 -3.289641 -1.748643 0.01061333 -3.872092 -0.488398 -3.627272 -2.521707 0.1164701 1.303374 -3.657476 -2.059095 -2.352496 -2.945384 -0.1982495 -2.391538 -2.953143 -0.9833586 -2.438837 -2.602777 -0.1934537 -3.127884 -3.477981 -2.757427 -4.04897 -2.859454 -3.27384 -2.495738 -3.258308 -2.576631 -2.390038 -3.196859 -3.2754 -2.5489 -2.376909 0.6323401 -0.03066489 -1.127135 -3.129769 -2.854264 -3.331671 -1.65677 -3.131075 -3.076578 -3.08638 -2.464041 1.437356 -3.573143 -2.271934 -2.472361 -0.4902505 -1.658275 -0.0325562 -4.357199 -1.980575 -3.171135 -4.330092 -3.184853 -3.898743 -4.063602 -3.877196 -2.259392 -3.046433 -3.253111 0.08185438 -1.639986 -1.855899 -3.182199 -2.536376 -0.04241286 0.1200429 -2.707349 -1.702393 -2.324123 -1.815255 -0.07592242 0.1701088 0.3831021 0.05513799 0.2442218 0.03865385 -0.02355409 -0.004849489 0.004649212 -0.07557817 -0.001901987 0.1010169 0.01132105 -0.01898369 0.00581637 0.0003628142 0.1184042 -0.1841824 -0.14097 -0.6152256 0.02022628 0.08026863 -0.01454854 -0.04967246 -0.0296229 -0.002572698 0.03316756 0.0001362216 -0.006167964 0.007078167 -0.0004072235 -0.02627413 #> Function value: -38558.81
endog <- ("lnprice") phat <- sorting_inst(s1.results, "lnprice", data, stepsize = 0.02)
#> Warning: package ‘bindrcpp’ was built under R version 3.4.1
#> [1] "iteration 1" #> [1] "sqrt dif max value: " #> [1] "0.10633" #> [1] "0.06328" #> [1] "0.032851" #> [1] "0.016162" #> [1] "0.0078435" #> [1] "0.0037948" #> [1] "0.0018362" #> [1] "0.00088968" #> [1] "0.00043183" #> [1] "iteration 2" #> [1] "sqrt dif max value: " #> [1] "0.89183" #> [1] "0.82855" #> [1] "0.55575" #> [1] "0.23394" #> [1] "0.086936" #> [1] "0.03435" #> [1] "0.014352" #> [1] "0.0061767" #> [1] "0.0026959" #> [1] "0.0011842" #> [1] "0.00052171" #> [1] "0.00023016" #> [1] "iteration 3" #> [1] "sqrt dif max value: " #> [1] "0.010344" #> [1] "0.0044851" #> [1] "0.0019635" #> [1] "0.00086341" #> [1] "0.00038045" #> 34 307 308 310 312 313 317 321 #> 11.58490 11.61966 11.79417 11.74903 11.66109 11.45457 11.64168 11.60150 #> 327 331 335 339 340 342 344 345 #> 11.69401 11.56534 11.57296 11.58292 11.62929 11.70122 11.63971 11.47382 #> 351 352 353 355 356 358 362 363 #> 11.58350 11.62280 11.61099 11.78080 11.67316 11.66515 11.81651 11.56122 #> 365 370 375 376 377 381 383 384 #> 11.66667 11.61580 11.57166 11.76982 11.98420 11.67313 11.62676 11.77748 #> 385 392 393 394 396 397 402 406 #> 11.51884 11.63168 11.66174 11.56373 11.67680 11.79186 11.69038 11.70083 #> 415 417 424 425 431 437 439 450 #> 11.62559 11.91127 11.74776 11.80202 11.56987 11.72106 11.59927 11.55220 #> 451 453 457 473 478 479 482 484 #> 11.62931 11.68327 11.70689 11.69832 11.62290 11.55747 11.57190 11.60269 #> 489 491 499 501 502 503 504 505 #> 11.57400 11.54253 11.51093 11.69379 11.65937 11.68212 11.56409 11.71965 #> 511 512 513 518 523 530 531 534 #> 11.61047 11.63044 11.55295 11.52689 11.48328 11.64071 11.51508 11.57529 #> 537 542 545 546 547 553 556 559 #> 11.47837 11.59005 11.61410 11.62338 11.65303 11.63343 11.48511 11.57208 #> 568 569 571 575 576 579 580 584 #> 11.60980 11.52972 11.58630 11.80018 11.62270 11.78437 11.54024 11.53447 #> 585 588 589 590 597 599 603 606 #> 11.54243 11.54787 11.53372 11.53999 11.64052 11.46218 11.75103 11.57034 #> 608 610 611 612 613 614 617 620 #> 11.58482 11.46340 11.51924 11.54066 11.63552 11.61058 11.50503 11.61671 #> 622 623 626 627 629 632 637 638 #> 11.42520 11.54274 11.76277 11.50069 11.98522 11.55269 11.58484 11.62854 #> 642 643 644 689 693 694 707 736 #> 11.55934 11.54519 11.55896 11.54902 11.54963 11.56944 11.56971 11.63860 #> 852 880 1525 1581 1621 1672 1696 1783 #> 11.66199 11.58532 11.57425 11.77370 11.54873 11.57897 11.71350 11.51685 #> 1842 1884 1892 1901 1904 1916 1926 #> 11.47692 11.54705 11.58623 11.53475 11.70212 11.68590 11.50918 #> #> Call: #> ivreg(formula = formula_iv, data = data_alt, weights = 1/se.weights) #> #> Residuals: #> Min 1Q Median 3Q Max #> -25.39717 -3.63648 0.07974 4.27760 19.50532 #> #> Coefficients: #> Estimate Std. Error t value Pr(>|t|) #> (Intercept) 322.6482 93.9647 3.434 0.000803 *** #> lnprice -26.9416 7.7619 -3.471 0.000708 *** #> kindergardens_1km 0.3002 0.3559 0.843 0.400537 #> p_mig_west 0.5586 0.1965 2.843 0.005203 ** #> nature 7.6055 3.5850 2.121 0.035810 * #> monuments 0.9410 0.3745 2.513 0.013215 * #> cafes_1km -0.4035 0.1633 -2.470 0.014822 * #> --- #> Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 #> #> Residual standard error: 7.624 on 128 degrees of freedom #> Multiple R-Squared: -4.699, Adjusted R-squared: -4.966 #> Wald test: 3.742 on 6 and 128 DF, p-value: 0.001831 #> #> [1] "Correlation with endogenous variable == 0.6669"
s2.results <- second_stage(s1.results, data) s2.results <- second_stage(s1.results, data, "lnprice", phat$sorting_inst)