Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create new variable of survey data

    Hello.
    I'm working with survey data from the Eurobarometer survey. I want to create a new variable, which will assign countries values based on Freedom House rankings for government transparency.
    I have tried using this code: generate govt = 3 if cntry_eu == 2, govt = 4 if cntry_eu == 3, govt = 2 if cntry_eu == 4 ........ etc.
    But stata only recognise one line of code, and when I tabulate the new variable it gives me the number of induviduals within that first country.
    How can I add on more values? And is it possible to add labels to the numeric country codes in the creating of the new variable, so that the results are easier to interpret?

    Many thanks for all kinds of help!

  • #2
    You could use -recode-. If, e.g., cntry_eu==1 is Austria and Austria has Freedom House ranking 1, cntry_eu==2 is Belgium and Belgium has Freedom House ranking 3 etc.,
    Code:
    clear
    set obs 4
    gen cntry_eu = _n
    
    recode cntry_eu (1=1) (2=3) (3=4) (4=2) ,gen(govt)
    
    la def cntry 1 "Austria" 2 "Belgium" 3 "Bulgaria" 4 "Croatia"
    la val cntry_eu cntry
    Last edited by Øyvind Snilsberg; 08 Dec 2021, 06:13.

    Comment

    Working...
    X