dimanche 31 mars 2019

How to index variables in loops in stata?

I am trying to replace entries of a variable 'personid' if the values of the other variables match each other. I usually code in python and r, so i tried to do this by indexing the variables and looping it. But it doesn't seem to work in Stata. Does anyone have advice? My code is below:

forvalues i=1/1545 {
if contestantname == contestantname[_n-1] & villageid == villageid[_n-1] & SeatCategory == SeatCategory[_n-1] {
    if  personid[_n-1] == . {
        replace personid[_n-1] == personid 
        }

    else if {replace personid == personid[_n-1]
        }
}

thanks!

Aucun commentaire:

Enregistrer un commentaire