vendredi 21 mai 2021

How to create a variable for when other variable takes up highest value, with conditions on countries?

I'm trying to create a new variable in a dataset under conditions on other variables. First, I have countries in Africa, with each country divided in constituencies for each I have the number of votes for a candidate.

I am trying to work for one country at a time (country=ctr) and to create the value in each constituency (cst)

I would like to create a variable win1 = 2 when the votes take the highest value in a given constituency, and in a given country.

I have created the variable win1

I have tried :

by cst : replace win1=2 if cv1=max(cv1) in (ctr==566)

It is my first time using stata, so please help me !

Thank you

Aucun commentaire:

Enregistrer un commentaire