Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(foreign)
- setwd("Z:/Econometrie")
- MyData <- read.spss('FESYOUTHSTUDYROMANIA.sav',to.data.frame=TRUE)
- View(MyData)
- backupdata=MyData
- grade<- MyData$e4
- hist(grade) # makes a histogram over the Height.Inches. variable
- mean(grade)
- median(grade)
- sd(grade)
- variance(grade)
- #Crosstabulation for two variables
- MyData.ctab<- table(MyData$dir,MyData$tenyr)
- MyData.ctab
- margin.table(MyData.ctab) # see total observations
- round(prop.table(MyData.ctab),4) # computes proportion with 4 decimals
- crosstab<-as.data.frame (round(prop.table(MyData.ctab),2)) # show proportion with 2 decimals into a table
- View(crosstab) # see the table
- # creating a data frame with the name of the variables
- attr(MyData, 'variable.labels')
- MyData.labels <- as.data.frame(attr(MyData, 'variable.labels'))
- #recode variables
- MyData$CopyOfc13_5 <- NA
- #create new data set with the research variables
- myvar<-subset(MyData, select= c("e4", "a7_5", "a7_1", "a7_2", "tenyr"))
- #remove NA value
- complete.cases(myvar) # shows true (if there is a value) or false (if there is not any value)
- sum(which (complete.cases(myvar))) #all the complete values
- sum(which (!complete.cases(myvar))) # all the incomplete values (! stands for not)
- research<- na.omit(myvar)
- sum(which (!complete.cases(research))) # if it is 0 then there are no NA values
- View(research)
- #check for other missing values in variable tenyr
- table(research$tenyr)
- # remove DK/NA values
- research[research$tenyr == 'DK/NA', 'tenyr']<- NA
- table(research$tenyr)
- sum(which (!complete.cases(research))) # check for NA values in tenyr
- research<- na.omit(research) # remove NA values in tenyr
- sum(which (!complete.cases(research))) #chek if NA values in tenyr are 0
- table(research$tenyr)
- View(research)
- #transform factor data as numerical data
- research$e4<-as.numeric(research$e4) # average grade last year
- research$a7_5<-as.numeric(research$a7_5) # money spend on books
- research$a7_1<-as.numeric(research$a7_1) # money spend on films
- research$a7_2<-as.numeric(research$a7_2) #money spend on bars
- # simple linear regression model
- lm(e4 ~ a7_5, data=research)
- #multiple regression model
- LRM<-lm(e4 ~ a7_5+a7_2+a7_1, data=research)
- LRM # to see the results of the equation
- View(LRM)
- summary(LRM) # to see the descriptive statistics and the equation model
- install.packages("lmtest") # after installation you need to go to packages and check the lmtest package to be functional or use library
- library (lmtest)
- dwtest(LRM)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement