Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. library(foreign)
  2. setwd("Z:/Econometrie")
  3.  
  4. MyData <- read.spss('FESYOUTHSTUDYROMANIA.sav',to.data.frame=TRUE)
  5. View(MyData)
  6.  
  7. backupdata=MyData
  8.  
  9. grade<- MyData$e4
  10.  
  11. hist(grade) # makes a histogram over the Height.Inches. variable
  12. mean(grade)
  13. median(grade)
  14. sd(grade)
  15. variance(grade)
  16.  
  17. #Crosstabulation for two variables
  18. MyData.ctab<- table(MyData$dir,MyData$tenyr)
  19. MyData.ctab
  20. margin.table(MyData.ctab) # see total observations
  21. round(prop.table(MyData.ctab),4) # computes proportion with 4 decimals
  22.  
  23. crosstab<-as.data.frame (round(prop.table(MyData.ctab),2)) # show proportion with 2 decimals into a table
  24. View(crosstab) # see the table
  25.  
  26. # creating a data frame with the name of the variables
  27. attr(MyData, 'variable.labels')
  28. MyData.labels <- as.data.frame(attr(MyData, 'variable.labels'))
  29.  
  30. #recode variables
  31. MyData$CopyOfc13_5 <- NA
  32.  
  33.  
  34. #create new data set with the research variables
  35. myvar<-subset(MyData, select= c("e4", "a7_5", "a7_1", "a7_2", "tenyr"))
  36.  
  37. #remove NA value
  38. complete.cases(myvar) # shows true (if there is a value) or false (if there is not any value)
  39. sum(which (complete.cases(myvar))) #all the complete values
  40. sum(which (!complete.cases(myvar))) # all the incomplete values (! stands for not)
  41. research<- na.omit(myvar)
  42. sum(which (!complete.cases(research))) # if it is 0 then there are no NA values
  43. View(research)
  44.  
  45. #check for other missing values in variable tenyr
  46. table(research$tenyr)
  47.  
  48. # remove DK/NA values
  49. research[research$tenyr == 'DK/NA', 'tenyr']<- NA
  50. table(research$tenyr)
  51. sum(which (!complete.cases(research))) # check for NA values in tenyr
  52. research<- na.omit(research) # remove NA values in tenyr
  53. sum(which (!complete.cases(research))) #chek if NA values in tenyr are 0
  54. table(research$tenyr)
  55. View(research)
  56.  
  57. #transform factor data as numerical data
  58. research$e4<-as.numeric(research$e4) # average grade last year
  59. research$a7_5<-as.numeric(research$a7_5) # money spend on books
  60. research$a7_1<-as.numeric(research$a7_1) # money spend on films
  61. research$a7_2<-as.numeric(research$a7_2) #money spend on bars
  62.  
  63.  
  64. # simple linear regression model
  65. lm(e4 ~ a7_5, data=research)
  66.  
  67. #multiple regression model
  68. LRM<-lm(e4 ~ a7_5+a7_2+a7_1, data=research)
  69. LRM # to see the results of the equation
  70. View(LRM)
  71. summary(LRM) # to see the descriptive statistics and the equation model
  72.  
  73. install.packages("lmtest") # after installation you need to go to packages and check the lmtest package to be functional or use library
  74. library (lmtest)
  75. dwtest(LRM)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement