Below will follow steps necessary to get a data base set up based on a data set provided.
4.0.1 Create a data dictionary
Copy and run the following to create a DataDictionary draft.
Change the var_name vector to the variable names of your own project and the same for instrument. Then export the DataDictionary draft and open the .ods file in a visual editor as LibreOffice.
require(readODS)
Loading required package: readODS
# Naming the different variables ("record_id" is the default name for the record number)var_name <-c("record_id","base_date","hypertension", "diabetes", "cohabitation","mrs_assessed","mrs_date","mrs_score","event_date","event_type") # Instrument/form name corresponding to the variablesinstrument =c("base","base","base","base","base","mrs","mrs","mrs","event","event")# Combining the vectors with default data in data frame(dd_draft <-data.frame(Variable...Field.Name=var_name,Form.Name=instrument,Field.Type ="text",Choices..Calculations..OR.Slider.Labels ="",Field.Label ="")) |> gt::gt()
Variable...Field.Name
Form.Name
Field.Type
Choices..Calculations..OR.Slider.Labels
Field.Label
record_id
base
text
base_date
base
text
hypertension
base
text
diabetes
base
text
cohabitation
base
text
mrs_assessed
mrs
text
mrs_date
mrs
text
mrs_score
mrs
text
event_date
event
text
event_type
event
text
# Exporting for manual manipulationwrite_ods(dd_draft,path = here::here("data/dd_draft.ods"))
4.0.2 Specify variable names etc.
Have a look at the demonstration file below for inspiration.
# Opens file with standard programsystem2("open", "data/dd_draft.ods")
Type or paste the needed information manually, save the file with a new name (I did “data/dd_draft_adds.ods”) and load it again.
(dd <- readODS::read_ods(here::here("data/dd_draft_adds.ods"), na =""))|> gt::gt()
Variable...Field.Name
Form.Name
Field.Type
Choices..Calculations..OR.Slider.Labels
Field.Label
record_id
base
text
NA
ID
base_date
base
text
NA
Inclusion date
hypertension
base
radio
Yes, No
Hypertension
diabetes
base
radio
Yes, No
Diabetes
cohabitation
base
radio
Yes, No
Cohabitation
mrs_assessed
mrs
radio
Yes, No
Assesed
mrs_date
mrs
text
NA
Assessment date
mrs_score
mrs
radio
0, 1, 2, 3, 4, 5, 6
mRS score
event_date
event
text
NA
NA
event_type
event
radio
TIA, AIS, ICH, SAH
NA
4.0.3 Format choices
Note the different Field.Type’s used and Choices... , called labels. Each label will have a raw value. And for each of these I will also ad an “Unknown” with a artificial value of 99. This is performed with a small script.
For radio buttons, I have written the different options to choose from. For variables with a score to choose from, I have written the scores, and these variables and only these variables are named something with “_score”. Variables with binary or other types of outcome, I have written the label.