I am trying to manipulate a text (.tex) document (a multiple-choice exam) in Stata, which I realize is a bit strange. I have copied the text to the data editor so that each line is an observation for the variable v1. I have found Stata quite handy for text manipulation, but I am stuck on one issue: I need to duplicate specific blocks of four observations (the MCQ choices) and insert them directly below the original, so that I can manipulate the correct answer. To do this, I thought to start by inserting four blank rows after each question, and then doing a replace. However, I haven't found a way to do this, including through the ingap command.
It is possible to identify each MCQ using strmatch because each question-line begins with "\mc", and likewise the block of choices ends with the same value "\end{MC}". Here is a snippet of the data:
I would like to manipulate the data so that it would now be:
It is possible to identify each MCQ using strmatch because each question-line begins with "\mc", and likewise the block of choices ends with the same value "\end{MC}". Here is a snippet of the data:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str145 v1 "%Label1: " "\mc The production possibility curve (PPC) represents the \_\_\_\_\_\_\_\_ combinations of goods that can be produced with available resources." "\begin{MC}" "\item minimum attainable" "\item maximum attainable" "\item only" "\item equitable" "\end{MC}" "%Label2: " "\mc A point on the production possibility curve (PPC) is \_\_\_\_ if it is outside of the curve." "\begin{MC}" "\item attainable and efficient" "\item attainable and inefficient" "\item unattainable" "\item \textbf{None of the above}" "\end{MC}" end
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str145 v1 "%Label1: " "\mc The production possibility curve (PPC) represents the \_\_\_\_\_\_\_\_ combinations of goods that can be produced with available resources." "\begin{MC}" "\item minimum attainable" "\item \textbf{maximum attainable}" "\item only" "\item equitable" "\end{MC}" "\begin{MC}" "\item minimum attainable" "\item \textbf{maximum attainable}" "\item only" "\item equitable" "\end{MC}" "%Label2: " "\mc A point on the production possibility curve (PPC) is \_\_\_\_\_\_\_\_\_ if it is outside of the curve." "\begin{MC}" "\item attainable and efficient" "\item attainable and inefficient" "\item unattainable" "\item \textbf{None of the above}" "\end{MC}" "\begin{MC}" "\item attainable and efficient" "\item attainable and inefficient" "\item unattainable" "\item \textbf{None of the above}" "\end{MC}" end
Comment