University of Zimbabwe: Time: 2 Hours
University of Zimbabwe: Time: 2 Hours
UNIVERSITY OF ZIMBABWE
HSTS204
BSc Honours in Statistics and Actuarial Science Level 2 HASC216
STATISTICAL COMPUTING 2
November/December 2019
Time : 2 hours
A1. (a) Explain the difference between input and output when typing a document in
LATEX and in Microsoft Word. [4]
(b) LATEX is the application used for typesetting dissertations in the Statistics De-
partment. Give any three advantages of using LATEX over word processors like
Microsoft Word. [3]
page 1 of 5
HSTS204/HASC216
(a) The above CSPro dictionary was used in a survey and the survey responses
data was saved in fixed format in the working folder as file hhdata.dat.
Write one STATA do-file with all the commands to perform the following tasks:
(i) Declare your delimiter and create a log named hsts204exam, which can
be opened in any plain text editor, such as Notepad. [2]
(ii) Import the .dat [2]
(iii) Label the data set as ‘Household data’. [1]
(iv) Label all variables. [2]
page 2 of 5
HSTS204/HASC216
(v) Insert a note for the variable A6: ‘The expenditure includes food, non food
and fees expenses for the household’. [2]
(vi) Label the values for Sex of head of household, where the following code
scheme applies: 1=Male, 2=Female. [2]
(vii) Compute the age of the head of household, name the variable agehhh and
label it accordingly. [2]
(viii) Recode the ages of the household heads into the following labelled cate-
gories : <18 Child head , 18-24 Young adult, 25-40 Lower middle
age , 41-59 Upper middle age, 60+ Elderly, name the
variable agehhCAT and label it accordingly [3]
(ix) Save your data naming the file using your UZ registration number. [1]
(x) Produce frequency tables for variable A1. [1]
(xi) Produce descriptive statistics for A5 . [2]
(xii) Regress A7 on A8. [2]
(xiii) Close your log file. [1]
(b) The same data set generated by the CSPro dictionary above was saved as a
comma delimited file (.csv) which has the variable names on the first row.
(i) Write the R command to import and store the data in the workspace. [2]
(ii) Variable A3 is a categorical variable with the following coding scheme:
1=single, 2=married, 3=widowed, 4=divorced, 5=separated.
Upon importation into R, variable A3 has been treated as an integer vari-
able. Write the commands to correct this and attach the value set to A3. [5]
page 3 of 5
HSTS204/HASC216
(e) Explain the uses of the following commands in R explicitly specifying the
arguments of the functions :
dpois(x, λ),
ppois(q, λ),
qpois(p, λ), and
rpois(n, λ) . [8]
(f) What does the STATA command clear do? [1]
(g) Give the STATA commands for converting a string variable to numeric speci-
fying the alternative options for the command. [2]
(h) Describe the five STATA windows you get when you start up STATA. [5]
B7. (a) What is an R script file and what command would you type to execute one? [2]
(b) Consider five numeric vectors of equal length in R: Y, X1, X2, X3, X4.
Give the R commands to display four plots of Y against each of the X’s on the
same page. [5]
(c) The standard structure of STATA commands usually follows the syntax:
[by varlist:] command [varlist] [=exp] [if exp] [in range] [weight]
[using filename] [,options] .
Describe any 3 syntax elements. [3]
(d) On the next page (page 5) of this question paper is an article. Write down what
you would type (text and commands) in LATEX to produce this document (the
whole page). [20]
END OF EXAMINATION
page 4 of 5
HSTS204/HASC216
UNIVERSITY OF ZIMBABWE
HSTS204/HASC216 LATEX Q6 Article
November 2019
(b)
yij = β0 + βˆ1 xi + β2 xj + ij (1)
α α2
(c) σ = β
σ1 = β6
1
Use it to classify yourself
page 5 of 5