As of December 31, 2015, there were 15,995 diagnosed and reported persons living with human immunodeficiency virus (HIV) who were residents of San Francisco, California at time of diagnosis. Approximately one quarter of men who have sex with men (MSM) in San Francisco are HIV-positive. Despite a high HIV burden, a higher proportion of HIV-positive San Franciscans are virally suppressed (72% in 2014 in San Francisco) than nationally (55% nationally in 2013), and 81% of all cases in San Francisco had at least one HIV viral load or CD4 test in 2014 (versus 71% nationally in 2013). Recently, new strategies have emerged to prevent HIV transmission, including post-exposure prophylaxis, treatment as prevention and pre-exposure prophylaxis (PrEP). With these new tools, the end of the HIV epidemic is within reach. New HIV diagnoses in San Francisco are now half of what they were a decade ago, down from 528 new HIV diagnoses in 2006 to 255 in 2015. The Getting to Zero (GTZ) consortium, formed in San Francisco after World AIDS Day in 2013, which is comprised of representatives from the San Francisco Department of Public Health, the University of California San Francisco, public and private medical providers, community based organizations, other San Francisco government agencies and people living with HIV (PLWH), aims to get to zero new HIV transmissions, zero HIV deaths and zero HIV stigma in San Francisco. My dissertation is aligned with the mission of the GTZ consortium.My dissertation seeks to address how the population dynamics of MSM (through migration and HIV serostatus) could affect the prevalence and incidence of HIV in San Francisco and may help explain why there is ongoing HIV transmission in the era of PrEP and treatment as prevention. The ability to migrate has increased for PLWH as survival markedly improved following introduction of combination antiretroviral therapy in 1996. Although there is a high frequency of migration among the general U.S. population and among PLWH in San Francisco, migration patterns of MSM in San Francisco have, to my knowledge, never been described. Output from the novel migration model outlined in Chapter 2 can be used to understand the dynamics of the MSM population in San Francisco and macro-level forces that could affect the prevalence and incidence of HIV in the population. Estimating the number of MSM by HIV status also allows researchers to have a denominator of this hidden population for use in estimating prevalence, incidence, service needs and funding allocations. Further, estimating the number of HIV-negative in-migrants relative to the overall MSM population is important because research has shown that recent MSM migrants to metropolitan areas are at increased risk of HIV acquisition because of higher risk behaviors. My results suggest that the overall MSM population and all the MSM subpopulations studied decreased in size from 2006 to 2014. Further, there were differences in migration patterns by race and by HIV serostatus.Next, given the goal of eliminating all transmission of HIV, I assessed the association between knowledge of an HIV-negative partner’s PrEP use and reported condomless anal sex (CAS) among sexually active MSM in San Francisco. In 2010, the iPrEx trial showed that a daily dose of tenofovir disoproxil fumerate (TDF) and emtricitabine (FTC) for HIV-negative persons in HIV serodiscordant relationships could reduce HIV transmission by 42%. In 2012, the FDA approved daily FTC/TDF for HIV prophylaxis. Although no increase in CAS was observed in the iPrEx trial, there is concern that expansion of PrEP could result in reduced condom use. The study population for iPrEx, individuals who consented to participate in a randomized-controlled trial, likely did not represent the general population of MSM. Furthermore, participants knew that they could have been randomized to receive a placebo and, therefore, it is not surprising that in this setting, no increase in CAS was observed. Recent research has focused on PrEP use and CAS reported by HIV-negative individuals on PrEP; no research to my knowledge has focused on PLWH’s reported condom use during sex if they know that their HIV-negative partner is on PrEP. I found that there was a higher prevalence of reported CAS and insertive condomless anal sex (ICAS) in partnerships that were either seroconcordant or serodiscordant with PrEP, compared to partnerships that were serodiscordant without PrEP. There was evidence that men in this sample were adapting their condom use based on their sexual partner’s HIV status and PrEP use, and their own viral suppression status. Discordant partnerships with PrEP had an increased adjusted prevalence of reported CAS and ICAS.I used causal inference methods to determine the effect of internalized HIV stigma (IHS) on viral suppression. Past research on IHS has focused on ART adherence as an outcome, and depression has been determined to be a mediator along this path. To my knowledge, no research has looked at the effect of IHS on viral suppression as an outcome. Research focusing on IHS in San Francisco has been limited to subgroups of HIV-positive individuals, such as homeless and marginally housed HIV-positive adults. Causal inference methods were used to estimate the counterfactual proportion of HIV-positive adults virally suppressed if all adults in HIV care in San Francisco did not experience IHS compared to the proportion of HIV-positive adults virally suppressed if all adults in HIV care in San Francisco did experience IHS, by following the causal roadmap. Three estimators were used to estimate the average treatment effect: simple substitution, inverse probability of treatment weighting, and targeted maximum likelihood estimation (TMLE). The results from each estimator were similar, and a statistically significant causal effect was observed for all. Using TMLE, the counterfactual proportion of adults virally suppressed would decrease by roughly 4.5% if all adults did not experience internalized HIV stigma as opposed to if all adults experience internalized HIV stigma.