ess <- read.csv("~/TOM_MCOA/ess.csv")

library(dplyr)
## 
## Attaching package: 'dplyr'
## 
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## 
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ade4)
library(adegraphics)
## 
## Attaching package: 'adegraphics'
## 
## The following objects are masked from 'package:ade4':
## 
##     kplotsepan.coa, s.arrow, s.class, s.corcircle, s.distri,
##     s.image, s.label, s.logo, s.match, s.traject, s.value,
##     table.value, triangle.class
library(foreign)

head(ess)
##   idno cntry                                             eisced
## 1  689    AL       4. ES-ISCED IIIa, upper tier upper secondary
## 2  776    AL                    2. ES-ISCED II, lower secondary
## 3  187    AL                    2. ES-ISCED II, lower secondary
## 4  230    AL                    2. ES-ISCED II, lower secondary
## 5  710    AL                    2. ES-ISCED II, lower secondary
## 6  894    AL 6. ES-ISCED V1, lower tertiary education, BA level
##                                        isco08
## 1 7231. Motor vehicle mechanics and repairers
## 2                       66666. Not applicable
## 3               4226. Receptionists (general)
## 4                       66666. Not applicable
## 5                          5141. Hairdressers
## 6                       66666. Not applicable
##                                        eiscedf
## 1 4. ES-ISCED IIIa, upper tier upper secondary
## 2 4. ES-ISCED IIIa, upper tier upper secondary
## 3 3. ES-ISCED IIIb, lower tier upper secondary
## 4              2. ES-ISCED II, lower secondary
## 5              2. ES-ISCED II, lower secondary
## 6              2. ES-ISCED II, lower secondary
##                                                  edulvlmb   pspwght
## 1    213. General ISCED 2A, access ISCED 3A general/all 3 1.0024704
## 2    213. General ISCED 2A, access ISCED 3A general/all 3 2.6222066
## 3 313. General ISCED 3A, access upper tier ISCED 5A/all 5 1.1224478
## 4 313. General ISCED 3A, access upper tier ISCED 5A/all 5 0.2413523
## 5    213. General ISCED 2A, access ISCED 3A general/all 3 1.3729354
## 6    213. General ISCED 2A, access ISCED 3A general/all 3 0.3146548
##     pweight sincome rincome pays
## 1 0.1860081       2       5   AL
## 2 0.1860081       3       1   AL
## 3 0.1860081       1       4   AL
## 4 0.1860081       3       3   AL
## 5 0.1860081       4       1   AL
## 6 0.1860081       2       2   AL
ess$w <- ess$pspwght*ess$pweight
ess$sincome <- as.factor(ess$sincome)
ess$rincome <- as.factor(ess$rincome)

df <- select(ess, eisced, isco08, eiscedf, sincome, rincome )
acm <- dudi.acm(df, row.w=ess$w, scannf=FALSE, nf=2)

plot(acm)

x <- acm$li

df2 <- cbind(x, ess)


write.dta(df2, "df2x.dta")
write.csv(df2, "df2x.csv")