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
Help with scatterplotIn Stata 17, how can I make a scatter plot of X and Y variables, showing two distinct groups as in t…
For-each loop to sum across groups of observationDear All, I have a dataset structured as follows. It is actually an Input Output (IO) matrix. So yo…
Implied cost of capital - mm_root with > 10 argumentsDear all, In the course of my Master's thesis I intend to calculate an implied cost of capital (ICC…
factor-variable and time-series operators not allowed r101Hello experts I'm trying to perform a Stratification-Multilevel analysis using the hte package. How…
Stratified Cox regression R vs. Stata - can R do more?Hi I am a regular Stata user, but I'll also looking into solving problems in R. Here, I have problem…
Subscribe to:
Post Comments (Atom)
0 Response to create new value based on variable name
Post a Comment