Dear members, hello again!
As a new Stata programmer, I have a new question, more about correct procedures and code:
- changing a variable type from date (%tm) back to a string, to adjust to pre-written code
- or, if should I even do that or go back and change initial data
I have code that I wrote for my research (with the help of many Statalist members, last year). This code uses several times interactions between two string variables (yrmonth, rtype)
For this new research, I prepared the data with yrmonth variable in %tm not in string. (The data this time around was initially in days. So, I extracted the yrmonth from a date %td.)
I see two solutions:
1) go back and change all the initial date to include a string field for month and year also (where now I have DMY dates),
2) change the date yrmonth format to string
What is the best practice suggested?
And if item 2, please, help me with this simple code:
For changing the date (yrmonth) to string, I tried:
Results came out like:
I am considering just leaving the data like this, since I will be using ordering and filtering for which Stata recognizes the periods.
Does anyone foresee a problem?
I am using Stata 12.1 for Mac.
Thank you for any tips!
Regards,
Clarice
As a new Stata programmer, I have a new question, more about correct procedures and code:
- changing a variable type from date (%tm) back to a string, to adjust to pre-written code
- or, if should I even do that or go back and change initial data
I have code that I wrote for my research (with the help of many Statalist members, last year). This code uses several times interactions between two string variables (yrmonth, rtype)
For this new research, I prepared the data with yrmonth variable in %tm not in string. (The data this time around was initially in days. So, I extracted the yrmonth from a date %td.)
I see two solutions:
1) go back and change all the initial date to include a string field for month and year also (where now I have DMY dates),
2) change the date yrmonth format to string
What is the best practice suggested?
And if item 2, please, help me with this simple code:
For changing the date (yrmonth) to string, I tried:
Code:
gen str_yrmonth=string(yrmonth)
Results came out like:
Code:
str_yrmonth 575 576 577 578
I am considering just leaving the data like this, since I will be using ordering and filtering for which Stata recognizes the periods.
Does anyone foresee a problem?
I am using Stata 12.1 for Mac.
Thank you for any tips!
Regards,
Clarice
Comment