View source: R/cto_form_dofile.R
| cto_form_dofile | R Documentation |
Creates a Stata .do file that applies variable labels, value labels, and
notes to a dataset based on the XLSForm definition of a SurveyCTO form.
The function supports multi-language forms, repeat groups, and
select_multiple questions, and generates Stata-compatible regular
expressions so labels are applied to all indexed variables.
cto_form_dofile(form_id, path = NULL)
form_id |
A character string specifying the SurveyCTO form ID. |
path |
Optional character string giving the output file path for the
generated |
The function performs several processing steps:
Language selection: Automatically chooses the default language defined in the XLSForm, or falls back to English when multiple label columns are present.
Value labels: Generates Stata label define commands for
all select_one choice lists and a binary label set for
select_multiple variables.
Repeat handling: For variables inside repeat groups,
Stata loops and regex matching are created so labels apply to all indexed
copies (for example, child_age_1, child_age_2).
Select-multiple expansion: Produces conditional labeling
logic for binary indicator variables derived from
select_multiple questions.
Label cleaning: Removes HTML markup, escapes Stata-special
characters, normalizes whitespace, and preserves SurveyCTO interpolation
strings such as ${var}.
A character vector containing the lines of the generated Stata .do file.
The value is returned invisibly.
Other Form Management Functions:
cto_form_attachment(),
cto_form_data(),
cto_form_data_attachment(),
cto_form_languages(),
cto_form_metadata()
## Not run:
# Generate a Stata do-file and write it to disk
cto_form_dofile("household_survey", path = "labels.do")
# Generate without writing to a file
cmds <- cto_form_dofile("household_survey")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.