Questions tagged [stata-macros]

A macro in Stata is comprised of a name and contents. When a properly punctuated macro name appears in a command or script, its contents are expanded and replace the macro name.

Macros in Stata can be distinguished in two flavours: global and local. Both are defined with the commands of the same name. The contents of the former can be expanded anywhere. In contrast, the latter are only available within a program or script where they were defined.

The chapter Macro definition and manipulation in the manual offers more detailed information.

For questions involving the use of macros in the context of Stata, please use the tag in addition to the main tag.

171 questions
-1
votes
1 answer

Referencing macro values by index

I defined the macros below as levels of the variables id, var1 and var2: levelsof id, local(id_lev) sep(,) levelsof var1, local(var1_lev) sep(,) levelsof var2, local(var2_lev) sep(,) I'd like to be able to reference the level values stored in…
kathystehl
  • 831
  • 1
  • 9
  • 26
-1
votes
1 answer

Stata macro read all data

I have the following do file: /* The following line should contain the complete path and name of the raw data file. On a PC, use backslashes in paths as in C:\ */ local dat_name "/homes/data/cps-basic/jan10pub.dat" /* The following line…
mustafghan
  • 169
  • 4
  • 15
-1
votes
2 answers

Local macros inside a loop

I am running a panel regression and I have to try combinations of variables. I have been trying to run the code below: local x0 elec_qtr_dummy local x1 elec_qtr_dummy elec_qtr_1b local x2 elec_qtr_dummy elec_qtr_1b elec_qtr_2b local x3…
-2
votes
1 answer

im currently using stata, and i dont know what code to use in particular. can someone help me solve this issue, the problem at hand is as follows :

We are interested in studying the impact of fertility on employment outcomes of adult men and women. We will start by constructing the main outcome variables of interest. Construct the following variables: (a) A dummy variable indicating if the…
-2
votes
1 answer

Stata reshape long to wide

I'm working with this type of data set in Stata: Year Country Investment Value 2000 US Bonds Total 8% 2000 US Bonds Private 50% 2000 US Equity Total 10% 2000 US Bonds Public 50% 2000 US Equity listed 30% 2000 US Equity…
Loni
  • 1
  • 1
-2
votes
3 answers

How do I generate age category? My PATIENT_YOB is given as 01jan1956 and I want to get exact age

I'm trying to use the following code but it gives error 01jan1986 05jan2001 07mar1983 and so on I need to get the exact age of them gen agecat=1 if age 0-20==1 if age 21-40==2 if age 41-60==3 if age 61-64==4```
san
  • 1
  • 2
1 2 3
11
12