Project

General

Profile

Support #1714

Merge the COVID19 survey waves

Added by amwaj abugamza almost 2 years ago. Updated 4 months ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
COVID-19
Start date:
06/09/2022
% Done:

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

merging COVID19 waves - long .do (969 Bytes) merging COVID19 waves - long .do amwaj abugamza, 06/09/2022 10:05 AM
C-19 long format.do (1000 Bytes) C-19 long format.do Understanding Society User Support Team, 06/10/2022 05:01 PM
c19 syntax changes.png (64.9 KB) c19 syntax changes.png Understanding Society User Support Team, 06/10/2022 05:01 PM
#1

Updated by Understanding Society User Support Team almost 2 years ago

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

#2

Updated by Understanding Society User Support Team almost 2 years ago

  • Status changed from New to Feedback
#3

Updated by Understanding Society User Support Team 4 months ago

  • Status changed from Feedback to Resolved

Also available in: Atom PDF