I have data on user ratings and am trying to see whether there is a downward trend at various cutting points of a user's reviews. In simpler terms, I want to see what proportion of users see a downward trend from their 1st and 2nd reviews compared to the rest of their reviews (in this case the cutting point is 2), 1st 2nd and 3rd reviews compared to the rest, 1st 2nd 3rd and 4th compared to the rest and so on. I am hoping to go up to 50 in terms of the cutting point. Here is the code I used to calculate this proportion with a cutting point of 2:
PHP Code:
*1-50
keep if rating_count >= 2
by userid: generate first_cut2 = 1 if rank[_n] == rank[1] | rank[_n] == rank[2]
by userid: generate second_cut2 = 1 if rank[_n] > rank[2]
by userid: egen first_cut_rating2 = mean(rating) if first_cut2 == 1
by userid: egen second_cut_rating2 = mean(rating) if second_cut2 == 1
by userid: gen difference_of_cuts2 = first_cut_rating2[1] - second_cut_rating2[_N-1]
by userid: gen downward_trend2 = 1 if difference_of_cuts2 > 0
by userid: replace downward_trend2 = 0 if difference_of_cuts2 < 0
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str17 userid double rating float(rank first_cut2 second_cut2 difference_of_cuts2 n2) "001544VKwW" 1 1 1 . . 1 "001544VKwW" 5 2 1 . . 1 "007pm3BK9b" 2 1 1 . -1.1029413 0 "007pm3BK9b" 3.5 2 1 . -1.1029413 0 "007pm3BK9b" 4 3 . 1 -1.1029413 0 "007pm3BK9b" 4 4 . 1 -1.1029413 0 "007pm3BK9b" 5 5 . 1 -1.1029413 0 "007pm3BK9b" 4 6 . 1 -1.1029413 0 "007pm3BK9b" 4 7 . 1 -1.1029413 0 "007pm3BK9b" 3.5 8 . 1 -1.1029413 0 "007pm3BK9b" 3 9 . 1 -1.1029413 0 "007pm3BK9b" 3.5 10 . 1 -1.1029413 0 "007pm3BK9b" 4 11 . 1 -1.1029413 0 "007pm3BK9b" 5 12 . 1 -1.1029413 0 "007pm3BK9b" 5 13 . 1 -1.1029413 0 "007pm3BK9b" 3.5 14 . 1 -1.1029413 0 "007pm3BK9b" 3 15 . 1 -1.1029413 0 "007pm3BK9b" 3 16 . 1 -1.1029413 0 "007pm3BK9b" 4 17 . 1 -1.1029413 0 "007pm3BK9b" 5 18 . 1 -1.1029413 0 "007pm3BK9b" 2 19 . 1 -1.1029413 0 "00BLGIWzcJ" 3 1 1 . -.4411764 0 "00BLGIWzcJ" 4 2 1 . -.4411764 0 "00BLGIWzcJ" 4.5 3 . 1 -.4411764 0 "00BLGIWzcJ" 5 4 . 1 -.4411764 0 "00BLGIWzcJ" 4 5 . 1 -.4411764 0 "00BLGIWzcJ" 1.5 6 . 1 -.4411764 0 "00BLGIWzcJ" 4 7 . 1 -.4411764 0 "00BLGIWzcJ" 4.5 8 . 1 -.4411764 0 "00BLGIWzcJ" 2.5 9 . 1 -.4411764 0 "00BLGIWzcJ" 4 10 . 1 -.4411764 0 "00BLGIWzcJ" 4.5 11 . 1 -.4411764 0 "00BLGIWzcJ" 5 12 . 1 -.4411764 0 "00BLGIWzcJ" 3.5 13 . 1 -.4411764 0 "00BLGIWzcJ" 5 14 . 1 -.4411764 0 "00BLGIWzcJ" 4 15 . 1 -.4411764 0 "00BLGIWzcJ" 4 16 . 1 -.4411764 0 "00BLGIWzcJ" 4 17 . 1 -.4411764 0 "00BLGIWzcJ" 3.5 18 . 1 -.4411764 0 "00BLGIWzcJ" 3.5 19 . 1 -.4411764 0 "00D0EXepFD" 4 1 1 . 1.0999999 1 "00D0EXepFD" 5 2 1 . 1.0999999 1 "00D0EXepFD" 3 3 . 1 1.0999999 1 "00D0EXepFD" 4 4 . 1 1.0999999 1 "00D0EXepFD" 2 5 . 1 1.0999999 1 "00D0EXepFD" 4 6 . 1 1.0999999 1 "00D0EXepFD" 4 7 . 1 1.0999999 1 "00FqmmCeLF" 5 1 1 . . 1 "00FqmmCeLF" 5 2 1 . . 1 "00GM0zPWrU" 4.5 1 1 . 0 . "00GM0zPWrU" 4 2 1 . 0 . "00GM0zPWrU" 4 3 . 1 0 . "00GM0zPWrU" 5 4 . 1 0 . "00GM0zPWrU" 4 5 . 1 0 . "00GM0zPWrU" 4 6 . 1 0 . "00GRD0DXsA" 3.5 1 1 . -.25 0 "00GRD0DXsA" 4 2 1 . -.25 0 "00GRD0DXsA" 4 3 . 1 -.25 0 "00GRD0DXsA" 4 4 . 1 -.25 0 "00I4u5rBjQ" 2.5 1.5 1 . . 1 "00I4u5rBjQ" 4 1.5 1 . . 1 "00M2bF7aW1" 5 1 1 . . 1 "00M2bF7aW1" 5 2 1 . . 1 "00M2bF7aW1" 5 3 . 1 . 1 "00M9ISXXrC" .5 1 1 . -1.888889 0 "00M9ISXXrC" 3.5 2 1 . -1.888889 0 "00M9ISXXrC" 3.5 3 . 1 -1.888889 0 "00M9ISXXrC" 2.5 4 . 1 -1.888889 0 "00M9ISXXrC" 3.5 5 . 1 -1.888889 0 "00M9ISXXrC" 3 6 . 1 -1.888889 0 "00M9ISXXrC" 3.5 7 . 1 -1.888889 0 "00M9ISXXrC" 5 8 . 1 -1.888889 0 "00M9ISXXrC" 5 9 . 1 -1.888889 0 "00M9ISXXrC" 5 10 . 1 -1.888889 0 "00M9ISXXrC" 4 11 . 1 -1.888889 0 "00OFXMYGwM" 5 1 1 . . 1 "00OFXMYGwM" 4.5 2 1 . . 1 "00P0wOQrpc" 3.5 1 1 . .41666675 1 "00P0wOQrpc" 5 2 1 . .41666675 1 "00P0wOQrpc" 4 3 . 1 .41666675 1 "00P0wOQrpc" 3 4 . 1 .41666675 1 "00P0wOQrpc" 4.5 5 . 1 .41666675 1 "00ROkedpRn" 4 1 1 . .05000019 1 "00ROkedpRn" 4.5 2 1 . .05000019 1 "00ROkedpRn" 4 3 . 1 .05000019 1 "00ROkedpRn" 4 4 . 1 .05000019 1 "00ROkedpRn" 4 5 . 1 .05000019 1 "00ROkedpRn" 4 6 . 1 .05000019 1 "00ROkedpRn" 5 7 . 1 .05000019 1 "00SGfJeiLC" 5 1 1 . 0 . "00SGfJeiLC" 5 2 1 . 0 . "00SGfJeiLC" 5 3 . 1 0 . "00SGfJeiLC" 5 4 . 1 0 . "00TAAjSt8W" 4 1 1 . . 1 "00TAAjSt8W" 3 2 1 . . 1 "00TAAjSt8W" 4 3 . 1 . 1 "00UQ1iBiDJ" 2.5 1.5 1 . -1.5 0 "00UQ1iBiDJ" 3 1.5 1 . -1.5 0 "00UQ1iBiDJ" 2 3 . 1 -1.5 0 "00UQ1iBiDJ" 5 4 . 1 -1.5 0 end
0 Response to Creating a loop with multiple operations
Post a Comment