Warning: package 'pglm' was built under R version 4.5.1
Loading required package: maxLik
Loading required package: miscTools
Please cite the 'maxLik' package as:
Henningsen, Arne and Toomet, Ott (2011). maxLik: A package for maximum likelihood estimation in R. Computational Statistics 26(3), 443-458. DOI 10.1007/s00180-010-0217-1.
If you have questions, suggestions, or comments regarding the 'maxLik' package, please use a forum or 'tracker' at maxLik's R-Forge site:
https://r-forge.r-project.org/projects/maxlik/
library(tidyverse)
Warning: package 'stringr' was built under R version 4.5.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::between() masks plm::between()
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks plm::lag(), stats::lag()
✖ dplyr::lead() masks plm::lead()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(texreg)
Warning: package 'texreg' was built under R version 4.5.1
Version: 1.39.4
Date: 2024-07-23
Author: Philip Leifeld (University of Manchester)
Consider submitting praise using the praise or praise_interactive functions.
Please cite the JSS article in your publications -- see citation("texreg").
Attaching package: 'texreg'
The following object is masked from 'package:tidyr':
extract
Warning: package 'censReg' was built under R version 4.5.1
Please cite the 'censReg' package as:
Henningsen, Arne (2017). censReg: Censored Regression (Tobit) Models. R package version 0.5. http://CRAN.R-Project.org/package=censReg.
If you have questions, suggestions, or comments regarding the 'censReg' package, please use a forum or 'tracker' at the R-Forge site of the 'sampleSelection' project:
https://r-forge.r-project.org/projects/sampleselection/
panelResult <-censReg( affairs ~ age + yearsmarried + religiousness + occupation + rating, left =0, right=Inf , data = Affairs, )
summary( panelResult )
Call:
censReg(formula = affairs ~ age + yearsmarried + religiousness +
occupation + rating, left = 0, right = Inf, data = Affairs)
Observations:
Total Left-censored Uncensored Right-censored
601 451 150 0
Coefficients:
Estimate Std. error t value Pr(> t)
(Intercept) 8.17420 2.74145 2.982 0.00287 **
age -0.17933 0.07909 -2.267 0.02337 *
yearsmarried 0.55414 0.13452 4.119 3.80e-05 ***
religiousness -1.68622 0.40375 -4.176 2.96e-05 ***
occupation 0.32605 0.25442 1.282 0.20001
rating -2.28497 0.40783 -5.603 2.11e-08 ***
logSigma 2.10986 0.06710 31.444 < 2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Newton-Raphson maximisation, 7 iterations
Return code 1: gradient close to zero (gradtol)
Log-likelihood: -705.5762 on 7 Df
# Tải gói cần thiếtlibrary(AER)
Warning: package 'AER' was built under R version 4.5.1
Loading required package: car
Warning: package 'car' was built under R version 4.5.1
Loading required package: carData
Warning: package 'carData' was built under R version 4.5.1
Attaching package: 'car'
The following object is masked from 'package:dplyr':
recode
The following object is masked from 'package:purrr':
some
Loading required package: lmtest
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
Loading required package: sandwich
Loading required package: survival
library(plm)# Giả sử bạn có dữ liệu panelset.seed(123)n <-100# Số lượng cá nhânT <-5# Số lượng thời gianid <-rep(1:n, each = T)time <-rep(1:T, n)X1 <-rnorm(n * T)X2 <-rnorm(n * T)epsilon <-rnorm(n * T, mean =0, sd =1)Y <-pmax(0, 5+2* X1 -3* X2 + epsilon) # Biến phụ thuộc với giới hạn từ 0# Tạo dataframeDatapanel <-data.frame(id, time, Y, X1, X2)
# Chuyển đổi dữ liệu thành dạng panelDatapanel <-pdata.frame(Datapanel, index =c("id", "time"))# Mô hình Tobittobit_model <-tobit(Y ~ X1 + X2, data = Datapanel, left =0)
# Tóm tắt kết quảsummary(tobit_model)
Call:
tobit(formula = Y ~ X1 + X2, left = 0, data = Datapanel)
Observations:
Total Left-censored Uncensored Right-censored
500 50 450 0
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 5.00857 0.04604 108.792 <2e-16 ***
X1 2.07645 0.04766 43.566 <2e-16 ***
X2 -2.97534 0.04843 -61.433 <2e-16 ***
Log(scale) -0.01364 0.03331 -0.409 0.682
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Scale: 0.9865
Gaussian distribution
Number of Newton-Raphson Iterations: 9
Log-likelihood: -655.3 on 4 Df
Wald-statistic: 5525 on 2 Df, p-value: < 2.22e-16
tobit_model2 <-censReg(Y ~ X1 + X2, data = Datapanel, left =0)