library(haven)
TEDS_2016<-read_stata("https://github.com/datageneration/home/blob/master/DataProgramming/data/TEDS_2016.dta?raw=true")

TEDS_2016$Tondu<-as.numeric(TEDS_2016$Tondu,labels=c("Unificationnow","Statusquo,unif.infuture","Statusquo,decidelater",
                                                     "Statusquoforever","Statusquo,indep.infuture","Independencenow","Noresponse"))

# Generate Frequency Table
table(TEDS_2016$Tondu)
## 
##   1   2   3   4   5   6   9 
##  27 180 546 328 380 108 121
# Barplot of Tondu Variable
barplot(TEDS_2016$Tondu, main="Frequency of Responses",
        xlab="Response Frequency",
        ylab="Response")

# Multiple Linear Regression to Explore Relationship between Tondu and other variables
explore <- lm(Tondu ~ age + female + DPP, data=TEDS_2016)
summary(explore) # show results
## 
## Call:
## lm(formula = Tondu ~ age + female + DPP, data = TEDS_2016)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.5414 -1.1640 -0.3789  0.8656  5.4216 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 3.253427   0.140359  23.179  < 2e-16 ***
## age         0.010484   0.002528   4.148 3.53e-05 ***
## female      0.491240   0.084980   5.781 8.85e-09 ***
## DPP         0.341330   0.088999   3.835  0.00013 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.743 on 1686 degrees of freedom
## Multiple R-squared:  0.03739,    Adjusted R-squared:  0.03568 
## F-statistic: 21.83 on 3 and 1686 DF,  p-value: 7.182e-14
# Multiple Linear Regression with income instead of DPP
explore2 <- lm(Tondu ~ age + female + income, data=TEDS_2016)
summary(explore2) # show results
## 
## Call:
## lm(formula = Tondu ~ age + female + income, data = TEDS_2016)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.8385 -1.1767 -0.4111  0.9705  5.4310 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  3.806978   0.175860  21.648  < 2e-16 ***
## age          0.008199   0.002581   3.176 0.001518 ** 
## female       0.466677   0.085058   5.487 4.72e-08 ***
## income      -0.058233   0.015855  -3.673 0.000247 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.743 on 1686 degrees of freedom
## Multiple R-squared:  0.0367, Adjusted R-squared:  0.03499 
## F-statistic: 21.41 on 3 and 1686 DF,  p-value: 1.302e-13
# Multiple Linear Regression with edu instead of income
explore3 <- lm(Tondu ~ age + female + edu, data=TEDS_2016)
summary(explore3) # show results
## 
## Call:
## lm(formula = Tondu ~ age + female + edu, data = TEDS_2016)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.8795 -1.0725 -0.4116  0.9992  5.5664 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  4.893961   0.257545  19.002  < 2e-16 ***
## age         -0.003801   0.003173  -1.198    0.231    
## female       0.441796   0.084293   5.241 1.80e-07 ***
## edu         -0.243427   0.036035  -6.755 1.96e-11 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.713 on 1676 degrees of freedom
##   (10 observations deleted due to missingness)
## Multiple R-squared:  0.05617,    Adjusted R-squared:  0.05448 
## F-statistic: 33.25 on 3 and 1676 DF,  p-value: < 2.2e-16
# Multiple Linear Regression 
explore4 <- lm(Tondu ~ Taiwanese + female + edu, data=TEDS_2016)
summary(explore4) # show results
## 
## Call:
## lm(formula = Tondu ~ Taiwanese + female + edu, data = TEDS_2016)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.0742 -1.0963 -0.2877  0.7432  5.9037 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  4.11799    0.12410  33.184  < 2e-16 ***
## Taiwanese    0.78268    0.08484   9.225  < 2e-16 ***
## female       0.37782    0.08255   4.577 5.07e-06 ***
## edu         -0.20433    0.02761  -7.400 2.15e-13 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.671 on 1676 degrees of freedom
##   (10 observations deleted due to missingness)
## Multiple R-squared:  0.101,  Adjusted R-squared:  0.0994 
## F-statistic: 62.77 on 3 and 1676 DF,  p-value: < 2.2e-16
# Multiple Linear Regression 
explore5 <- lm(Tondu ~ Taiwanese + female + Econ_worse, data=TEDS_2016)
summary(explore5) # show results
## 
## Call:
## lm(formula = Tondu ~ Taiwanese + female + Econ_worse, data = TEDS_2016)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.7556 -1.1450 -0.3203  0.6797  5.6797 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  3.51557    0.08831  39.809  < 2e-16 ***
## Taiwanese    0.82469    0.08704   9.475  < 2e-16 ***
## female       0.41538    0.08386   4.953 8.03e-07 ***
## Econ_worse  -0.19522    0.08439  -2.313   0.0208 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.713 on 1686 degrees of freedom
## Multiple R-squared:  0.07027,    Adjusted R-squared:  0.06861 
## F-statistic: 42.47 on 3 and 1686 DF,  p-value: < 2.2e-16
# Correlation between Tondu and votetsai
tsai_cor <- lm(Tondu ~ votetsai, data=TEDS_2016)
summary(tsai_cor) # show results
## 
## Call:
## lm(formula = Tondu ~ votetsai, data = TEDS_2016)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.3785 -1.3588 -0.3588  0.6215  5.6412 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  3.35881    0.06918   48.55   <2e-16 ***
## votetsai     1.01967    0.08741   11.67   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.501 on 1259 degrees of freedom
##   (429 observations deleted due to missingness)
## Multiple R-squared:  0.09755,    Adjusted R-squared:  0.09683 
## F-statistic: 136.1 on 1 and 1259 DF,  p-value: < 2.2e-16