Sesión 4

Espacio de trabajo y librerías

setwd("C:/Users/socgt/Downloads/Nueva carpeta")
library(stargazer)
library(officer)
library(flextable)
library(haven)
library(Hmisc)
library(jtools)

Cargar datos

bdatos1 <- read_dta("base_datos_1.dta")
bdatos2 <- read_dta("base_datos_2.dta")
bdatos3 <- read_dta("base_datos_3.dta")
bdatos4 <- read_dta("base_datos_4.dta")
bdatos5 <- read_dta("base_datos_5.dta")
bdatos6 <- read_dta("base_datos_6.dta")
bdatos7 <- read_dta("base_datos_7.dta")
bdatos8 <- read_dta("base_datos_8.dta")
bdatos9 <- read_dta("base_datos_9.dta")
bdatos10 <- read_dta("base_datos_10.dta")

Modelos de Regresión

modelo1 <- lm(ventas ~ gasto_marketing, data = bdatos1)
modelo2 <- lm(beneficio ~ costos_produccion, data = bdatos2)
modelo3 <- lm(satisfaccion_cliente ~ calidad_producto, data = bdatos3)
modelo4 <- lm(productividad ~ horas_capacitacion, data = bdatos4)
modelo5 <- lm(ingresos ~ gasto_publicidad, data = bdatos5)
modelo6 <- lm(participacion_mercado ~ precio_producto, data = bdatos6)
modelo7 <- lm(retorno_inversion ~ inversion_investigacion, data = bdatos7)
modelo8 <- lm(costo_adquisicion ~ gasto_publicidad_adquisicion, data = bdatos8)
modelo9 <- lm(tasa_conversion ~ experiencia_usuario, data = bdatos9)
modelo10 <- lm(crecimiento_ventas ~ estrategia_precios, data = bdatos10)

Mostrar resúmenes de los modelos

summary(modelo1)
## 
## Call:
## lm(formula = ventas ~ gasto_marketing, data = bdatos1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4996.7  -950.9   122.9   925.6  3784.5 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     19015.765   2374.349   8.009 2.11e-11 ***
## gasto_marketing     2.227      0.470   4.739 1.14e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1803 on 68 degrees of freedom
## Multiple R-squared:  0.2483, Adjusted R-squared:  0.2372 
## F-statistic: 22.46 on 1 and 68 DF,  p-value: 1.136e-05
summary(modelo2)
## 
## Call:
## lm(formula = beneficio ~ costos_produccion, data = bdatos2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5854.3 -1232.1     9.2  1246.0  4593.6 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)        4.722e+04  1.309e+03   36.09   <2e-16 ***
## costos_produccion -1.308e+00  8.471e-02  -15.44   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1983 on 68 degrees of freedom
## Multiple R-squared:  0.7781, Adjusted R-squared:  0.7749 
## F-statistic: 238.5 on 1 and 68 DF,  p-value: < 2.2e-16
summary(modelo3)
## 
## Call:
## lm(formula = satisfaccion_cliente ~ calidad_producto, data = bdatos3)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -10.4104  -2.7916  -0.2765   3.4442  11.6585 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       52.8851     3.8157   13.86   <2e-16 ***
## calidad_producto   9.7085     0.4631   20.96   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.734 on 68 degrees of freedom
## Multiple R-squared:  0.866,  Adjusted R-squared:  0.864 
## F-statistic: 439.5 on 1 and 68 DF,  p-value: < 2.2e-16
summary(modelo4)
## 
## Call:
## lm(formula = productividad ~ horas_capacitacion, data = bdatos4)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -14.1366  -4.1023   0.3369   4.3863  14.9858 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)         66.3593     5.3595  12.382  < 2e-16 ***
## horas_capacitacion   0.9559     0.1758   5.438 7.91e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.257 on 68 degrees of freedom
## Multiple R-squared:  0.3031, Adjusted R-squared:  0.2928 
## F-statistic: 29.57 on 1 and 68 DF,  p-value: 7.907e-07
summary(modelo5)
## 
## Call:
## lm(formula = ingresos ~ gasto_publicidad, data = bdatos5)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6180.9 -2513.5    89.6  2343.2  6401.4 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      3.922e+04  1.649e+03   23.79   <2e-16 ***
## gasto_publicidad 1.875e+00  1.678e-01   11.17   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3073 on 68 degrees of freedom
## Multiple R-squared:  0.6474, Adjusted R-squared:  0.6422 
## F-statistic: 124.8 on 1 and 68 DF,  p-value: < 2.2e-16
summary(modelo6)
## 
## Call:
## lm(formula = participacion_mercado ~ precio_producto, data = bdatos6)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -101.556  -30.046   -5.192   24.159  108.386 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     487.4902    24.0953  20.232  < 2e-16 ***
## precio_producto  -3.8997     0.4557  -8.558 2.13e-12 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 43.71 on 68 degrees of freedom
## Multiple R-squared:  0.5185, Adjusted R-squared:  0.5115 
## F-statistic: 73.23 on 1 and 68 DF,  p-value: 2.13e-12
summary(modelo7)
## 
## Call:
## lm(formula = retorno_inversion ~ inversion_investigacion, data = bdatos7)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -9813.0 -2530.8  -310.6  3087.5  8129.6 
## 
## Coefficients:
##                          Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             3.062e+04  1.860e+03   16.46   <2e-16 ***
## inversion_investigacion 9.990e-02  8.904e-03   11.22   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3866 on 68 degrees of freedom
## Multiple R-squared:  0.6493, Adjusted R-squared:  0.6441 
## F-statistic: 125.9 on 1 and 68 DF,  p-value: < 2.2e-16
summary(modelo8)
## 
## Call:
## lm(formula = costo_adquisicion ~ gasto_publicidad_adquisicion, 
##     data = bdatos8)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -763.20 -229.19    3.72  202.37  765.59 
## 
## Coefficients:
##                                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                  1661.16082  164.93271  10.072 4.08e-15 ***
## gasto_publicidad_adquisicion   -0.57506    0.07969  -7.216 5.78e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 320.2 on 68 degrees of freedom
## Multiple R-squared:  0.4337, Adjusted R-squared:  0.4253 
## F-statistic: 52.07 on 1 and 68 DF,  p-value: 5.782e-10
summary(modelo9)
## 
## Call:
## lm(formula = tasa_conversion ~ experiencia_usuario, data = bdatos9)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.48842 -0.14001  0.02112  0.16752  0.41340 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)         -0.16678    0.11542  -1.445    0.153    
## experiencia_usuario  0.53944    0.02288  23.573   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1985 on 68 degrees of freedom
## Multiple R-squared:  0.891,  Adjusted R-squared:  0.8894 
## F-statistic: 555.7 on 1 and 68 DF,  p-value: < 2.2e-16
summary(modelo10)
## 
## Call:
## lm(formula = crecimiento_ventas ~ estrategia_precios, data = bdatos10)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -773.48 -232.61    2.98  250.90  642.31 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)        5002.335    179.453  27.875  < 2e-16 ***
## estrategia_precios    9.925      1.740   5.703 2.79e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 320.6 on 68 degrees of freedom
## Multiple R-squared:  0.3235, Adjusted R-squared:  0.3136 
## F-statistic: 32.52 on 1 and 68 DF,  p-value: 2.792e-07

Crear tablas personalizadas con la librería “jtools”

summ(modelo1)
Observations 70
Dependent variable ventas
Type OLS linear regression
F(1,68) 22.46
0.25
Adj. R² 0.24
Est. S.E. t val. p
(Intercept) 19015.77 2374.35 8.01 0.00
gasto_marketing 2.23 0.47 4.74 0.00
Standard errors: OLS
summ(modelo2)
Observations 70
Dependent variable beneficio
Type OLS linear regression
F(1,68) 238.48
0.78
Adj. R² 0.77
Est. S.E. t val. p
(Intercept) 47224.45 1308.57 36.09 0.00
costos_produccion -1.31 0.08 -15.44 0.00
Standard errors: OLS
summ(modelo3)
Observations 70
Dependent variable satisfaccion_cliente
Type OLS linear regression
F(1,68) 439.46
0.87
Adj. R² 0.86
Est. S.E. t val. p
(Intercept) 52.89 3.82 13.86 0.00
calidad_producto 9.71 0.46 20.96 0.00
Standard errors: OLS
summ(modelo4)
Observations 70
Dependent variable productividad
Type OLS linear regression
F(1,68) 29.57
0.30
Adj. R² 0.29
Est. S.E. t val. p
(Intercept) 66.36 5.36 12.38 0.00
horas_capacitacion 0.96 0.18 5.44 0.00
Standard errors: OLS
summ(modelo5)
Observations 70
Dependent variable ingresos
Type OLS linear regression
F(1,68) 124.84
0.65
Adj. R² 0.64
Est. S.E. t val. p
(Intercept) 39220.11 1648.53 23.79 0.00
gasto_publicidad 1.88 0.17 11.17 0.00
Standard errors: OLS
summ(modelo6)
Observations 70
Dependent variable participacion_mercado
Type OLS linear regression
F(1,68) 73.23
0.52
Adj. R² 0.51
Est. S.E. t val. p
(Intercept) 487.49 24.10 20.23 0.00
precio_producto -3.90 0.46 -8.56 0.00
Standard errors: OLS
summ(modelo7)
Observations 70
Dependent variable retorno_inversion
Type OLS linear regression
F(1,68) 125.88
0.65
Adj. R² 0.64
Est. S.E. t val. p
(Intercept) 30622.00 1860.26 16.46 0.00
inversion_investigacion 0.10 0.01 11.22 0.00
Standard errors: OLS
summ(modelo8)
Observations 70
Dependent variable costo_adquisicion
Type OLS linear regression
F(1,68) 52.07
0.43
Adj. R² 0.43
Est. S.E. t val. p
(Intercept) 1661.16 164.93 10.07 0.00
gasto_publicidad_adquisicion -0.58 0.08 -7.22 0.00
Standard errors: OLS
summ(modelo9)
Observations 70
Dependent variable tasa_conversion
Type OLS linear regression
F(1,68) 555.71
0.89
Adj. R² 0.89
Est. S.E. t val. p
(Intercept) -0.17 0.12 -1.45 0.15
experiencia_usuario 0.54 0.02 23.57 0.00
Standard errors: OLS
summ(modelo10)
Observations 70
Dependent variable crecimiento_ventas
Type OLS linear regression
F(1,68) 32.52
0.32
Adj. R² 0.31
Est. S.E. t val. p
(Intercept) 5002.33 179.45 27.88 0.00
estrategia_precios 9.93 1.74 5.70 0.00
Standard errors: OLS

Crear tablas personalizadas con la librería “stargazer”

stargazer(modelo1, title = "Modelo estimado", type = "text")
## 
## Modelo estimado
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                               ventas           
## -----------------------------------------------
## gasto_marketing              2.227***          
##                               (0.470)          
##                                                
## Constant                   19,015.760***       
##                             (2,374.349)        
##                                                
## -----------------------------------------------
## Observations                    70             
## R2                             0.248           
## Adjusted R2                    0.237           
## Residual Std. Error     1,803.476 (df = 68)    
## F Statistic           22.458*** (df = 1; 68)   
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01
stargazer(modelo2, title = "Modelo estimado", type = "text")
## 
## Modelo estimado
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                              beneficio         
## -----------------------------------------------
## costos_produccion            -1.308***         
##                               (0.085)          
##                                                
## Constant                   47,224.450***       
##                             (1,308.570)        
##                                                
## -----------------------------------------------
## Observations                    70             
## R2                             0.778           
## Adjusted R2                    0.775           
## Residual Std. Error     1,983.251 (df = 68)    
## F Statistic           238.476*** (df = 1; 68)  
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01
stargazer(modelo3, title = "Modelo estimado", type = "text")
## 
## Modelo estimado
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                        satisfaccion_cliente    
## -----------------------------------------------
## calidad_producto             9.709***          
##                               (0.463)          
##                                                
## Constant                     52.885***         
##                               (3.816)          
##                                                
## -----------------------------------------------
## Observations                    70             
## R2                             0.866           
## Adjusted R2                    0.864           
## Residual Std. Error       4.734 (df = 68)      
## F Statistic           439.456*** (df = 1; 68)  
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01
stargazer(modelo4, title = "Modelo estimado", type = "text")
## 
## Modelo estimado
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                            productividad       
## -----------------------------------------------
## horas_capacitacion           0.956***          
##                               (0.176)          
##                                                
## Constant                     66.359***         
##                               (5.360)          
##                                                
## -----------------------------------------------
## Observations                    70             
## R2                             0.303           
## Adjusted R2                    0.293           
## Residual Std. Error       6.257 (df = 68)      
## F Statistic           29.574*** (df = 1; 68)   
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01
stargazer(modelo5, title = "Modelo estimado", type = "text")
## 
## Modelo estimado
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                              ingresos          
## -----------------------------------------------
## gasto_publicidad             1.875***          
##                               (0.168)          
##                                                
## Constant                   39,220.110***       
##                             (1,648.528)        
##                                                
## -----------------------------------------------
## Observations                    70             
## R2                             0.647           
## Adjusted R2                    0.642           
## Residual Std. Error     3,072.887 (df = 68)    
## F Statistic           124.842*** (df = 1; 68)  
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01
stargazer(modelo6, title = "Modelo estimado", type = "text")
## 
## Modelo estimado
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                        participacion_mercado   
## -----------------------------------------------
## precio_producto              -3.900***         
##                               (0.456)          
##                                                
## Constant                    487.490***         
##                              (24.095)          
##                                                
## -----------------------------------------------
## Observations                    70             
## R2                             0.519           
## Adjusted R2                    0.511           
## Residual Std. Error      43.711 (df = 68)      
## F Statistic           73.235*** (df = 1; 68)   
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01
stargazer(modelo7, title = "Modelo estimado", type = "text")
## 
## Modelo estimado
## ===================================================
##                             Dependent variable:    
##                         ---------------------------
##                              retorno_inversion     
## ---------------------------------------------------
## inversion_investigacion          0.100***          
##                                   (0.009)          
##                                                    
## Constant                       30,622.010***       
##                                 (1,860.262)        
##                                                    
## ---------------------------------------------------
## Observations                        70             
## R2                                 0.649           
## Adjusted R2                        0.644           
## Residual Std. Error         3,865.767 (df = 68)    
## F Statistic               125.880*** (df = 1; 68)  
## ===================================================
## Note:                   *p<0.1; **p<0.05; ***p<0.01
stargazer(modelo8, title = "Modelo estimado", type = "text")
## 
## Modelo estimado
## ========================================================
##                                  Dependent variable:    
##                              ---------------------------
##                                   costo_adquisicion     
## --------------------------------------------------------
## gasto_publicidad_adquisicion          -0.575***         
##                                        (0.080)          
##                                                         
## Constant                            1,661.161***        
##                                       (164.933)         
##                                                         
## --------------------------------------------------------
## Observations                             70             
## R2                                      0.434           
## Adjusted R2                             0.425           
## Residual Std. Error               320.181 (df = 68)     
## F Statistic                    52.072*** (df = 1; 68)   
## ========================================================
## Note:                        *p<0.1; **p<0.05; ***p<0.01
stargazer(modelo9, title = "Modelo estimado", type = "text")
## 
## Modelo estimado
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                           tasa_conversion      
## -----------------------------------------------
## experiencia_usuario          0.539***          
##                               (0.023)          
##                                                
## Constant                      -0.167           
##                               (0.115)          
##                                                
## -----------------------------------------------
## Observations                    70             
## R2                             0.891           
## Adjusted R2                    0.889           
## Residual Std. Error       0.198 (df = 68)      
## F Statistic           555.708*** (df = 1; 68)  
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01
stargazer(modelo10, title = "Modelo estimado", type = "text")
## 
## Modelo estimado
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                         crecimiento_ventas     
## -----------------------------------------------
## estrategia_precios           9.925***          
##                               (1.740)          
##                                                
## Constant                   5,002.335***        
##                              (179.453)         
##                                                
## -----------------------------------------------
## Observations                    70             
## R2                             0.324           
## Adjusted R2                    0.314           
## Residual Std. Error      320.571 (df = 68)     
## F Statistic           32.519*** (df = 1; 68)   
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01