Hi all,
I have a dataset with variable names from taxdebt_20120101 to taxdebt_20131231 with the last digits being a date format. Those variables display values from 0 - 100,000
I am trying to create a new variable that equals the date of the variable name if the value of that variable is > 0.
My code so far:
gen date = .
forval j = 20120101/20131231 {
replace date = `j' if taxdebt_`j' > 0
}
tostring date, replace format(%20.0f)
gen date2 = date(date,"YMD")
format date2 %td
Unfortunately the code doesn't quite work. I keep getting the date 20120132. A date is also displayed for values = 0.
Hope you can help.
Related Posts with create new value based on variable name
Margins with tobit for elasticity estimatesI am running a tobit regression to model education expenditures (zero forsome households) and tried …
The meaning of cov option in meglm model?I‘m learning the meglm for GLMMs. I noticed that we can use the "cov" option to define the variance-…
Extracting the Beta Coeff from regressionHello all, I am running a linear regression, with 2 sets of dummy variables age (25-65) and cohort(…
Force empty observations to be included in analysis?If you have data that was collected with the intent all observations be used in analysis because eac…
Doubts on how to correctly declare a dataset to be survival timeDear all, I am a new Stata user and this is the first time I use this forum. I need to conduct a s…
Subscribe to:
Post Comments (Atom)
0 Response to create new value based on variable name
Post a Comment