Support #1714
openMerge the COVID19 survey waves
100%
Description
Hi
I am trying to merge the COVID19 survey waves into long format using stata based on the syntax provided in the link below.
https://www.understandingsociety.ac.uk/documentation/mainstage/syntax
After merging the waves, I am facing a problem with wave numbers. It is the same for all the waves (value=0), could you please help me spot the issues in my stata-do file (attached).
BW
Files
Updated by Understanding Society User Support Team over 2 years ago
- File C-19 long format.do C-19 long format.do added
- File c19 syntax changes.png c19 syntax changes.png added
- Category set to COVID-19
- % Done changed from 0 to 100
- Private changed from Yes to No
Hello,
The problem arises here:
"foreach w in ca cb cc cd ce cf ck cg ch ci {
// find the wave number
local waveno=strpos("abcdefghijklmnopqrstuvwxyz","`w'")"
When going through the subsequent iterations of the loop, Stata replace `w' with ca (1st iteration), cb (2nd iteration), cc (3rd iteration) and so on, instead of a, b, c, ..., and this can't produce a meaningful result. The strpos("abcdefghijklmnopqrstuvwxyz", "`w'") returns the position of the characters you specify in the `w' part in the string "abcdefghijklmnopqrstuvwxyz" counting from the left. When the loop is correctly specified, in the 1st iteration Stata replaces "`w'" with "a", then strpos returns the value of 1 which saved in the local macro waveno, in the 2nd iteration Stata replaces the "`w'" with "b", then strpos returns the value of 2 again saved in the local macro waveno and so on. The value of the local waveno is then passed to the variable wave created in line 25 (gen wave=`waveno'), in 1st iteration wave=1, in the 2nd wave=2 and so on.
I've corrected the file (attached), I'm also attaching the comparison of your original file with all the corrections marked so you can see what changes and where were necessary (your original file is on the right).
Best wishes,
Understanding Society User Support Team
Updated by Understanding Society User Support Team over 2 years ago
- Status changed from New to Feedback
Updated by Understanding Society User Support Team about 1 year ago
- Status changed from Feedback to Resolved