Hi Statalist. I am running Stata 14.2 on Windows.
I have a long dataset with vars:
The code I am using is below. The problem with the code is that Stata is only calculating the difference score for the last variable in the local varlist I'm defining.
preserve
keep group post stanund_*
collapse stanund_*, by(group post)
format stanund_* %9.2f
foreach var of varlist stanund_* {
reshape wide stanund_*, i(group) j(post)
gen diff_`var'=`var'1-`var'0
format diff_* %9.2f
}
*
restore
I tried also creating a local list of the varnames using the following code, but then I get an error complaining that the var stub is too ambiguous, which I'm confused by since it looks like I'm marking them as "diff" "0" or "1". (I got this idea from the thread at http://www.stata.com/statalist/archi.../msg00945.html.)
local myvars
foreach var of varlist stanund_* {
local x `x' `var'
}
*Make sure my local list contains the varnames I expect - which it does
di "`x'"
keep group post `x'
collapse stanund_*, by(group post)
format `x' %9.2f
reshape wide `x', i(group) j(post)
foreach var of varlist `x' {
gen diff_`x'=`x'1-`x'0
}
.
stanund_techprof ambiguous abbreviation
r(111);
Any idea on how to get what I want? Thanks in advance.
I have a long dataset with vars:
- Group = observations are associated with one of three groups
- Post = pre-assessment (0) and post-assessment (1)
- Outcomes = ordinal ratings across a series of vars that start with the prefix "standund_" (for "understanding of standards")
The code I am using is below. The problem with the code is that Stata is only calculating the difference score for the last variable in the local varlist I'm defining.
preserve
keep group post stanund_*
collapse stanund_*, by(group post)
format stanund_* %9.2f
foreach var of varlist stanund_* {
reshape wide stanund_*, i(group) j(post)
gen diff_`var'=`var'1-`var'0
format diff_* %9.2f
}
*
restore
I tried also creating a local list of the varnames using the following code, but then I get an error complaining that the var stub is too ambiguous, which I'm confused by since it looks like I'm marking them as "diff" "0" or "1". (I got this idea from the thread at http://www.stata.com/statalist/archi.../msg00945.html.)
local myvars
foreach var of varlist stanund_* {
local x `x' `var'
}
*Make sure my local list contains the varnames I expect - which it does
di "`x'"
keep group post `x'
collapse stanund_*, by(group post)
format `x' %9.2f
reshape wide `x', i(group) j(post)
foreach var of varlist `x' {
gen diff_`x'=`x'1-`x'0
}
.
stanund_techprof ambiguous abbreviation
r(111);
Any idea on how to get what I want? Thanks in advance.
Comment