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
Bayesian approach: what to do when it differs from the frequentist approach?Dear Forum Members, I'm somewhat puzzled by the results given from 2 down-to-earth models, one usin…
compare substrings in same var - same same, but differentHi. I have a problem with a huge list of >19,000 towns. There are > 1,200 towns with duplicat…
Making new variable from first letter of string variableHi Statalist, Thanks for being a great forum which already has helped a lot! I'm new here, quite f…
Different regression methods to proofHello, I have a question regarding different regression methods to proof my assumption. I want to k…
add legend to one of the graphs in -graph combine-Dear all statalisters, I now face a problem in dealing with drawing a combined graph with adding a l…
Subscribe to:
Post Comments (Atom)
0 Response to create new value based on variable name
Post a Comment