Hello,
I've got a dataset with rows specific to an individual and columns specific to certain themes (coded as 0 (no) or 1 (yes) depending on whether the theme was reported). I want to generate a new variable that is a summary of all the themes reported so I can quickly compare how many people reported each theme and also look at variations in the frequencies of themes across specific demographic groups. To create a single variable that captures all the themes reported, I have done the following:
gen all_themes=.
replace all_themes=0 if theme1==1
replace all_themes=1 if theme2==1
replace all_themes=2 if theme3==1
etc
However this fails to capture multiple themes that have been reported by the same person (if they report theme1 and theme3 they would only be recorded as having theme3 based on the (probably very inefficient) method I'm using above).
Any advice would be greatly appreciated.
With many thanks,
Johanna
Related Posts with Creating new variable across rows
Generating a financial year variable using nested loop Hi, My dataset has both 'year' and 'month' information for some variables. I want to generate a 'fi…
Three-way InteractionsI am working with following panel data linear regression model: y = f(x,y,z) + other control variabl…
replacing missing values with a specific year observationHello everyone, I need some help in composing a code for replacing missing values with the value of …
Error code 451: repeated time values within panel when trying to declare data to be panel dataI have a dataset which contains 18 quarterly datasets from the Labour Force Survey which have been m…
Stata code for Ellison, Glaeser (1997) and Krugman (1991)Hi All, I am trying to calculate the regional specialization and industry concentration following E…
Subscribe to:
Post Comments (Atom)
0 Response to Creating new variable across rows
Post a Comment