Code:
* Example generated by -dataex-. For more info, type help dataex clear input str35 imdbcastlink str36 imdbfilmlink str121 imdbgenre float(movies_tag gen_Action gen_Adult gen_Animation) "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0040021" "Drama" 1 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0042727" "Drama" 2 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0044081" "Drama" 3 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0045296" "Biography, Drama, History, Western" 4 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0045943" "Drama, History" 5 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0047677" "Crime, Drama, Romance" 6 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0047296" "Crime, Drama, Thriller" 7 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0046903" "Biography, Drama, History, Romance" 8 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0044284" "Drama, History, Music" 9 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0048140" "Comedy, Crime, Musical, Romance" 10 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0049830" "Comedy, Drama" 11 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0050933" "Drama, Romance" 12 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0052415" "Action, Drama, War" 13 1 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0052832" "Drama, Romance" 14 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0055257" "Drama, Western" 15 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0056264" "Adventure, Drama, History, Romance" 16 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0056632" "Adventure, Drama, Thriller" 17 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0057878" "Comedy" 18 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0059470" "Action, Drama, Thriller, War" 19 1 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0060232" "Crime, Drama, Thriller" 20 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0060120" "Action, Drama, Romance, Western" 21 1 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0061523" "Comedy, Romance" 22 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0062185" "Drama, Romance, Thriller" 23 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0062776" "Adventure, Comedy, Fantasy" 24 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0064728" "Action, Crime, Drama, Thriller" 25 1 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0064866" "Action, Drama, War" 26 1 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0069007" "Drama, Horror, Thriller" 27 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0068646" "Crime, Drama" 28 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0070849" "Drama, Romance" 29 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0074906" "Drama, Western" 30 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0809488" "Crime, Drama, Thriller" 31 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0078346" "Action, Adventure, Sci-Fi" 32 1 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0078678" "Biography, Drama, History, War" 33 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0078788" "Drama, Mystery, War" 34 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0080754" "Crime, Thriller" 35 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0839995" "Action, Adventure, Romance, Sci-Fi" 36 1 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0097243" "Drama, Thriller" 37 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0099615" "Comedy, Crime" 38 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0103962" "Adventure, Biography, Drama, History" 39 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0112883" "Comedy, Drama, Romance" 40 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0116654" "Horror, Sci-Fi, Thriller" 41 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0118768" "Drama" 42 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0120678" "Comedy, Crime" 43 0 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0227445" "Action, Crime, Drama, Thriller" 44 1 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt0442674" "Action, Crime, Drama" 45 1 0 0 "http://www.imdb.com/name/nm0000008" "http://www.imdb.com/title/tt10905860" "Animation, Comedy" 46 0 0 1 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0014187" "Crime" 1 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0015750" "Adventure" 2 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0016449" "Western" 3 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0016430" "Western" 4 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0016288" "Action, Drama, Western" 5 1 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0015766" "Action, Comedy, Romance, Western" 6 1 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0016534" "Western" 7 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0016052" "Western" 8 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0016480" "Western" 9 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0015772" "Action, Adventure, Comedy, Drama, History, Romance" 10 1 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0016453" "Comedy, Drama, Western" 11 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0177353" "Western" 12 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0017212" "Drama" 13 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0016641" "Adventure, Drama, Romance" 14 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0017465" "Romance" 15 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0016823" "Western" 16 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0017010" "Drama" 17 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0017400" "Western" 18 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0017530" "Drama, Comedy" 19 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0170688" "Western" 20 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0017567" "Drama, Romance, Western" 21 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0017226" "Drama, History" 22 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0016618" "Western" 23 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0018033" "Comedy, Romance" 24 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0017751" "Drama, Romance" 25 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0017637" "Western" 26 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0018578" "Drama, Romance, War, Action" 27 1 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0018080" "Western" 28 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0018199" "Western" 29 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0018681" "Adventure, Romance" 30 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0018846" "Drama, Romance" 31 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0019080" "Action, Drama, Romance, War" 32 1 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0018971" "Adventure, Drama, Romance" 33 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0019098" "Drama, Romance, War" 34 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0018892" "Drama, Romance" 35 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0019375" "Drama, Romance, War" 36 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0020595" "Drama, Western" 37 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0019687" "Drama" 38 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0020556" "Romance, Western" 39 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0021357" "Adventure, Drama, War" 40 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0021219" "Drama, Romance, War" 41 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0021232" "Comedy, Music" 42 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0021463" "Western" 43 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0021112" "Action, Drama, Romance, War" 44 1 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0021412" "Action, Western" 45 1 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0021156" "Drama, Romance" 46 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0021861" "Western" 47 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0021750" "Crime, Drama, Film-Noir, Romance" 48 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0021988" "Drama, Romance" 49 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0021963" "Drama, Romance" 50 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0023175" "Comedy, Drama, Romance" 51 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0022814" "Drama" 52 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0023049" "Comedy, Drama" 53 0 0 0 "http://www.imdb.com/name/nm0000011" "http://www.imdb.com/title/tt0022879" "Drama, Romance, War" 54 0 0 0 end
I am trying to run a loop for to calculate, for each actor/actress, the similarity in the usage of genres over their career.
As of now, I am using the following loop to go over each actorid:
preserve
forvalues i = 1(1)60000 {
keep if actorid == `i'
tempfile copy
save `copy'
rangejoin movies_tag 1 . using `copy', by (actorid) prefix(U_)
reshape long gen_ U_gen_, i(actorid movies_tag U_movies_tag) j(genre) string
by actorid movies_tag U_movies_tag, sort: egen both = total(gen_ & U_gen_)
by actorid movies_tag U_movies_tag: egen either = total(gen_ | U_gen_)
gen Jaccard = both/either
by actorid movies_tag U_movies_tag, sort: keep if _n == 1
by actorid (U_movies_tag movies_tag), sort: gen long seq = _n
by actorid (U_movies_tag movies_tag), sort: gen wanted = sum(Jaccard)/seq
by actorid U_movies_tag (seq), sort: keep if _n == _N
keep actorid U_movies_tag wanted
save "...\Actor_Filmography_`i'.dta", replace
restore, preserve
}
While each loop only takes about 20 seconds to run,
it often stops during the iterations, and even with 20 seconds to run each loop it would take about 2 weeks to do one iteration.
Would there be a way to more efficiently process the information I need?
Thank you again for your valuable time.

Comment