Stata command for renaming media files

For Stata and SurveyCTO users who are looking for a way to easily rename collected media files, we have good news! We have created such a command that can greatly ease your efforts if you’re in the habit of collecting media attachments, including images, audio, video, and text files.

This SurveyCTO resource for Stata users is significantly based on the work of a pre-existing resource for Stata users created by Innovations for Poverty Action (IPA). Both resources achieve the same aims but the SurveyCTO version has been tailored for more general use, compared to the specific requirements of IPA projects. 

Using this Stata command, you will be able to:

  • Create copies of SurveyCTO media files in a specified folder with names constructed from values stored in your dataset.
  • Organize the above media files into sub-folders, also constructed from values in your dataset.
  • Add conditionality to perform the above tasks with some but not all records.

This resource, which only works with data exported using SurveyCTO Desktop, 1) creates a local folder named ‘media’ with all collected media files and 2) includes the file path (‘media\filename’) in the dataset. Data exported directly from the server console webpage or via the API contains URLs to files as opposed to just the file names assumed by this command.

Getting started

The sctomedia command is included in the scto Stata package, where you can find other Stata commands to make the most of data collected using SurveyCTO. All information and codes are available on https://github.com/surveycto/stata-scto.

 If you never installed our scto package...

To install, type ssc install scto in the Stata command window.

 If you’ve already installed our scto package...

To update, type ado update scto, update in the Stata command window.

 To read associated documentation, type help sctomedia into the Stata command window.

Syntax

To run the command, follow the syntax below and adjust it according to your dataset:

sctomedia varname [if] [in], [by(varlist)] id(varname) vars(varlist) media(folder_path) output(folder_path) resolve(varname)

Example 

sctomedia audio_audit, id(hhid) vars(district village) by(enumeratorid) media(`source') output(`destination')

In this example, the sctomedia command is being run to rename and organize the media files stored in the variable 'audio_audit', which is an audio audit field. This dataset is the result of a household survey, where "hhid" is the unique identifier of the households, "enumeratorid" stores the unique identifier of the enumerator, and "district" and "village" store the district and village of the household, respectively. This code will trigger the following actions:

  • In `source', copy all media files matching the names stored in "audio_audit".
  • Inside `destination', create one folder for each enumeratorid and store the media files accordingly.
  • Renames all media files according to the sequence: `hhid'_`district'_`village'. This naming will use values, not labels.

Note that if your unique identifier id() has duplicates, you’re required to use resolve()

We hope that you find this command useful! Please consider sharing your experiences in our user forum.

0 Comments

Article is closed for comments.