Gauging public opinion is never straightforward, but it's even more difficult in a country racked by sectarian conflict, and haunted by militia death squads. Joe Twyman, who ran polling organisation YouGov's Baghdad bureau, explains.

No child grows up dreaming of being a pollster. Those who do grow up to be pollsters rarely aspire to work in Iraq, a place synonymous with conflict, violence and death.

However, that is precisely what I ended up doing in 2007, at the height of the sectarian violence with the country edging towards civil war, as director of YouGov's polling operations in Baghdad.

Flying into Baghdad for the first time I was certain that I was going to die. There was no anti-aircraft fire, no missile lock, no alarms blaring and no flak. It was just a commercial civilian flight, but the plane was performing a manoeuvre I later discovered was called a "corkscrew landing" - coming into the runway in a rapid spiral to avoid being hit by mortars.

The vast majority of people on that first flight appeared to be working as private security contractors, hefty and tattooed. They were used to it. For me it was new, and deeply unnerving.

About the author Joe Twyman was director of YouGov's office in Baghdad. Between 2007 and 2010, his team researched attitudes towards the emerging democracy for organisations including the UN and the Iraqi Electoral Commission.

As a fair-haired, 6ft 4in (1.9m) Englishman who spoke no Arabic it was inevitable that I would stand out, despite being encouraged to grow a moustache in order to "fit in". This took eight weeks and the general consensus was that it left me looking not like an Iraqi but a cross between a WWI pilot and a flasher.

So, instead of going out on the streets with piles of questionnaires, I was responsible for running the research behind the scenes. YouGov was the first company to conduct research in Baghdad after the fall of Saddam.

We were hired by a range of organisations, including the United Nations, the Iraqi Electoral Commission and a number of private sector clients, to survey the Iraqi public on a variety of issues.

These encompassed the political (election surveys) and social - asking about peoples' sewage, water, electricity and rubbish collection services - to the commercial, such as what type of soft drinks people liked.

Whether you're researching shampoo in London or electoral registration in Basra, good research is always based on asking the right questions of the right people.

A great deal of our time and resources were devoted to accurately modelling the numerous socio-demographic nuances of the Iraqi population. This was so we would be certain that the views of people of all ages, backgrounds and different parts of the country were represented.

Given the ethnic sensitivities, it was vital to hire and develop our own field force of locals to conduct face-to-face interviews. We recruited a team of researchers, many of whom became my friends and were, without doubt, the bravest and most intelligent people I will ever have the privilege of knowing.

The practicalities of surveying public opinion in the UK and Iraq are as different as you could imagine. I ran the polling for the Iraqi parliamentary elections in January 2010 and also the British general election in May 2010. One of the major differences is that when a Lib Dem threatens to kill you, he or she probably doesn't mean it.

Some regions, some cities and some areas were more difficult to reach than others but often the solution could be found through a combination of innovative thinking and sheer determination.

Usually it would take longer than we would hope and was nearly always more difficult than we had originally anticipated. We were often undertaking polling where no maps existed and instead had to give our teams randomly generated routes to follow.

Our interviewers faced the constant threat of kidnap and death. I vividly recall talking to one of our team on the phone as the building he was in was visited by a militia death squad. They would have killed anyone they found working for a foreign company and there were tense moments until he called back to say the gang had left without carrying out a systematic search.

I'm often asked if it was dangerous. It was. But danger is a very strange concept. You take all possible precautions but you also adjust to the relative danger that the situation presents.

You could regularly hear lots of small arms fire and explosions, particularly at night. Very nasty things may be going on nearby but you feel safe because they are not right in front of you.

You tend to get used to living in dangerous circumstances, otherwise you would spend the whole time terrified. Once you've done a few corkscrew landings, they start to feel perfectly normal. Even old commercial aircraft can do the most amazing things.

When I first went out there, civilian killings were at their peak; a real low point. As time moved on, things definitely did get better and the people - while not returning to "normality" - often did find a way, through incredibly difficult circumstances, to get on with their lives.

For me, the greatest illustration of progress was that when I arrived all that was on TV was news reports of violence and death. By the time I left, there was a Candid Camera-style show on one of the channels with the set-up that someone was led to believe they were travelling in a car packed with explosives, only for it to be revealed as a practical joke.

Image caption Rival militias fought for supremacy over large areas of Iraq

Slowly the democratic situation improved, at least a little, as did the provision of local services. The role of militias and al-Qaeda declined. Elections were held but the fundamental problems of sectarian division were never really addressed and I think progress has really stalled of late. I fear that the country may slip back to the bad times.

We, meanwhile, developed our polling from scratch. We developed the capacity to conduct nationally-representative public opinion surveys across Iraq, among all ages and in all 18 governorates. It was a full-service research agency employing over 100 Iraqis.

The interviewers heard a lot of conspiracy theories and rumours. One we heard was that America invaded Iraq because of oil, but Britain helped because it needed doctors and that "80% of doctors in Britain" were Iraqis. When asked if he had any proof of this he said he didn't need proof "because it was a fact".

However, my favourite result came when we ran a short question asking people how satisfied they were with their life on a 0 to 10 scale. The average figures for Iraq were noticeably higher than they were in Britain.

The reason for this was the context in which the different populations answered the question. In Britain you might be dissatisfied because you have lost your job or because you're short of money. In Iraq at that time, simply being alive was cause for a certain degree of satisfaction. It really brought things home to me.

Joe Twyman was director of YouGov's office in Baghdad. Between 2007 to 2010, his team researched attitudes towards the emerging democracy for organisations including the UN and the Iraqi Electoral Commission.

You can follow the Magazine on Twitter and on Facebook