Hi Bugz, Stata has a command that allows you to rename a group of variables. I would rename variables using this command and not use any looping constructs. Here is an example: sysuse auto, clear rename (make price mpg rep78 headroom trunk /// weight length turn displacement gear_ratio foreign) /// (v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12) You can read about the command by entering help rename group in the command window. You don't say much about how you want to construct your dummy variables but I can give you two examples. The first uses numeric variables as inputs and divides them at their means, assigning 0 if a value is less than or equal to the mean and a 1 if it is greater than the mean and not missing. I put the variable generation in a loop. Here is the example: sysuse auto, clear foreach var of varlist price mpg weight { summarize `var', meanonly generate `var'dum = `var' >= r(mean) & `var'
🤩thank you so much for the very clear and extensive answer. I have several categories in the dummy. So as your suggestion it is the tabulate command I used. gen v114=waters_dummyd tabulate waters_dummyd, gen(water_srca) gen imp_water_dd=1 if water_srca1==1 replace imp_water_dd=1 if water_srca2==0 For this, if there are categories from 1 - 20 I need to retype it 20 times and change the 1 or 0. I was wondering if I should do this way manually or if is there a macro to make this in a few lines.
@@bugzdesilva8216 I am confused by your code. I belive that your first two lines of code can be replaced by a single command like this: tabulate v114, gen(water_srca) You do not have to create a new variable to tabulate. Here is how this works with the auto.dta dataset: sysuse auto, clear tab rep78, generate(rep78dum_) Because the variable rep78 has 5 categories, a total of 5 dummy variables are created. The variables form a linear combination so something like a regression model you would need to decide on a category to exclude. Nota bene: if using indicator variables in some model, you really should use Stata's factor notation (see help fvvarlist). Your next two commands are confusing to me because I do not know how the original variable, v114, was coded. It looks like you are trying to take two conditions and code them equal to 1 and all other equal to zero. Here is an example, again, using rep78: sort rep78 generate rep78dum = cond(1, rep78==1 | rep78==5, 0) if rep78
@@smilex3 Thank you so much !!! The last example you provided was really helpful to me. It solved the problem I faced. I was generating a binary variable assigning 1 or 0 per category to the main variable (ie: rep78). Your command made my dofile clear and smooth. Glad I'm following your channel !!
@smilex3 And one more clarification please. if we want to generate a categorical variable by using the rep78 variable, giving 1 if rep78==1 and 2 if rep78==2 and 3 if rep78==3 and 0 for both rep78==4 and rep78==5 how could we generate the above categories using the same command. Is it possible.. *sort rep78 generate rep78dum = cond(1, rep78==1 | rep78==5, 0) if rep78
Thank you for your video. I would like to ask about bootstrapping. Could you give me an example that how to bootstrap with the foreach loop. For instance, to get standard error for elasticities from multiple regression. Thank you.
Is it possible that you can post some video about example how to do 30 regression estimate for the Dowjones stocks in just a short time rather than doing it by manually loading each firms data repeatedly over and over. and doing each seperate regression and then pile it in one file. have you some pointers on how to do such sort of a thing,
Hi Alan, Seeking your help in constructing a foreach loop. I have a pair of datasets (A & B) for each year from 2001 through 2010. I want to run a set of commands for database A for a given year first, then merge it with dataset B of same year. I want to repeat this for each year from 2001 through 2010. Appreciate your help. Thanks.. Alok
I'm trying to run below matrix of concentration index (ci). However, following error came up. Could you advise what's wrong with it. type mismatch r(109); end of do-file r(109); sum r [aw=hhweight] sca v_rank=r(Var) foreach var of varlist count* { sum `var' [aw=hhweight] sca m_`var'=r(mean) gen d_`var'=(2*v_rank)*(`var'/m_`var') quietly { regr d_`var' rank matrix coefs=get(_b) gen ci_`var'=coefs [1,1] If "`var'"=="count5" { matrix ci=coefs [1, 1] } if "`var'"~=̏count5̋ { matrix ci=(ci, coefs[1,1]) } } }
Otgon, This error message implies that either you are trying to numerically manipulate a string variable or apply a string operation to a numeric variable. The following Stata code demonstrates this idea. So, you will need to look at your variables and decide if you need to convert some or all to numerics or to strings. Here is the example code. Run one line at a time since the second generate will fail with an error. Best, Alan /* Stata Code Follows */ sysuse auto, clear describe mpg make generate log_mpg=log(mpg) /* This works */ generate log_make=log(make) /* Data mismatch */ generate mpg_len=strlen(mpg) /* Data mismatch */
Hi, Alan. Thanks for these videos! Can I use macro to regress in loop of firm and save the residuals of the regression as a variable using the minimum of 8 firms? What is the stata command for that? Thanks! Ana
+Carolina Vargas I don't have a video explicitly about this but if you type "help forvalues" in the command window you can get a brief introduction. Do you have a specific problem in mind that we may be able to teas out together?
+Alan Neustadtl Im currently in a stata class and have to do some work. I have a data base(colombian) that is showing for each region the types of taxes and how much was recieved for each type of tax each year by region. So the variable nabes are something like this: region | type_ of_ tax | 2000 | 2001 | 2002 | 2003 | 2004 | there are 33 types of tax. they ask me to create a loop using "forvalues" with a sequence for each type of tax that has the following: 1) Number of iterations as big as the number of types of taxes (so 33) 2). Use command "summ" 3) extract the descriptive stats from each and save them in a matrix **the matrix was created before and on the rows names were the types of tax and columns are mean sd min max sum. Right now the matrix is composed of "." I dont know if this is very confusing
+Carolina Vargas So, this is a little confusing to me, but here is a try at using forvalues to produce descriptive statistics for different groups using the built-in auto.dta dataset: sysuse auto, clear forvalues i=1(1)5 { summarize mpg if rep78==`i' } This ignores putting the results into a matrix which is more complicated. I know that the variable rep78 ranges from 1 to 5 so I can summarize another variable, mpg in this example, when rep78=1, then when rep78=2, and so forth. But, in Stata this kind of operation can often be accomplished more simply using other means. This is probably not within the scope of your assignment, but the same out put can be achieved with just a single line of Stata code: bysort rep78: summarize mpg if rep78!=. And, this has the advantage of further grouping your summarized statistics. Here you can see the descriptive statistics of mpg broken down by foreign and domestic and within those categories by the five categories of rep78: bysort foreign rep78: summarize mpg if rep78!=. Is the first example what you needed?
Dear Alan. Thank you for a great video. I have tried to replicate the commands you use in your video with regression models. In my own dataset I have created a list of independent vars and stored them in a local macro that I include in several logistic regression models that each include different dependent variables. What I realized (at least I think I did) is that you have to create the local macro as well as run all the models including the local macro at once, i.e. you have to run several lines from your do-file in one go (as you do as well in your video). Is it possible to create a macro, which does not require that you run all of these commands at once? E.g. you may first create the local macro of independent variables, then spend some time doing some summary statistics, inspecting your data etc. and then, later in the stata session, run a model using the specified local macro of the independent variables. I hope this makes sense. Thank you very much. Kind regards, Martin (Denmark).
Greatings Professor, thank you so much for your videos. They are really clarifying to me. I was wondering, why in the 41th line, don't you have to use the "`'" quotes to use the e() macros?.
julián, for reasons unknown to me, you do not need the special quotes on these Stata generated local macros. For example, the following all produce the same result with the exception that the last example is a string while the first two are numbers: sysuse auto, clear regress mpg weight di e(mss) di `e(mss)' di "`e(mss)'" Best, Alan'
Hi Alan, I followed your instruction for constructing macro ( referring to your do file 27-30) but it's not working ( I am using STATA 14). Can you please suggest . I used the following command for my variables : ** hofstede to refer to the following three variables ** local hofstede Power_Distance Individualism Masculinity di `hofstede' reg WoB_Proportion `hofstede' However the regression result is not showing coefficients for the three independent variables. Please suggest. Thanks in advance.
Shams, without seeing the error from your program I can't be very specific about how to fix the issue. That said, the problem I see most often is the incorrect use of quoting in local macros. The left quote is not really a quote. It is the symbol underneath the tilde key. This is the tilde "~" and this is the quote on the same key "`". The right quote is " ' ". Here is some reproducible Stata code that works: sysuse auto, clear local ivs weight displacement regress mpg `ivs' Best, Alan
Thank you Alan. I tried the same quote you mentioned. I cannot upload the error msg in the youtube comment box, is there any other way I can send you the snapshot of the error?
Dear Alan. First, thanks for your videos!!!... I am trying to create a macro and foreach loop with the command spmap, but always STATA send the message "too many variables specified". This is the code: local mld mldc_ilpc mldc_iapc mldc_impc format `mld' %12.2f foreach var of varlist `mld' { spmap `mld' using comunascoord, id(id) clmethod(q) legend(size(medium) position(7)) fcolor(Blues2) graph save `mld' }
Javier, I cannot replicate your error. I adapted your code to run with the auto.dta dataset and it runs fine. Can you use that dataset and replicate your error? Then I might be able to dig a little deeper. I also wonder why you are using macros at all in your code with so few variables you could just use the format command. See the second to last line of the code below for an example. Best, Alan sysuse auto, clear desc length turn displacement local mld length turn displacement format `mld' %12.2f desc length turn displacement format length turn displacement %8.0g desc length turn displacement
the `r(N)' and other scalars seems like a fantastically silly way for STATA to store these data. How can I look at the objects stored within r(), e(), etc? It seem like there should be a useful way of looking at what is stored in these lists before I'd use them...? For example, I have a "flexible" stat summary table with rows, columns, and super columns. When I type "return list" after this table the only piece it shows is `r(N)' - where's the rest?
Jeff van Geete Unfortunately, there is no rest. When Stata commands are written, the developer decides what, if any, results are stored as local macros. In the case of the table command (I think this is what you are referring to) only one result, the sample size, is saved as a scalar. I am not certain if this is silly (fantastically) or not, but saved results in macros are often very useful if you want to use these results in your own programming to calculate something outside of the command, proper. Best, Alan
Alan Neustadtl As in most other stat programs / packages, I agree that having the results is useful for later calculation. For example, all (lm) linear models in R contain these results in their structure, without having to issue an extra command. I quite like Stata, but on this one issue look no further than the curious assignment of ` and ' (I can think of no other language that demands dissimilar quotes). Truly head-scratching.
Jeff van Geete I am not sure why you find using `' to delimit local macros. All programming languages have these kind of programming syntax. Suppose you could define a local macro as "local #newmacro r(N)" and then refer to it as "#newmacro". How is the decision to use a pound symbol to refer to macros any less curious than using ` and ' delimiters? Unfortunately, all programming languages do what they do regardless of our dreams, wishes, and desires! So, for many of us that means learning the ins and outs and curiosities of many programming languages.
Alan Neustadtl if a language wanted you to use ( and ] to open and close arguments, would you think that's odd? why use mismatched quotes? just to be different? programming languages are supposed to follow a discernible (and yes, learnable) logic, almost rule #1 - or? i use `language function()` all the time in markdown (as in `r nrow(data)`), as has been standard since probably before my time. matching these opening and closing symbols is standard - or should be.
No more odd than many, many other programming conventions which is exactly my point. What is odd in R to me is not to an R programmer. What is odd to the R programmer in Stata is not to me. And no, using ( and ] is no more odd than using ` and ' or #macroname . I suppose that using the accent grave and a quote may have been selected as delimiters since they are similar, but not equal to single and double quote pairs. But I speculate, and my wishes and desires for what Stata "should do" are of no consequence--Stata does what it does (same for all other programming languages.
A great Canadian singer-songwriter named Stan Rogers. One of my favorite songs of his is called "Northwest Passage". Prime Minister Stephen Harper called it the unofficial national anthem of Canada. You can listen to it here: ua-cam.com/video/Fk2cNWW5FU0/v-deo.html
Alan Neustadtl, you could try "Alt+96" and/or "Alt+39" for the apostraphes. For even smoother workflow with your surface pro2, you could assign those to an autohotkey. Having said that, I am pretty sure you can find the apostraphes even without using the alt-combinations. It will probably just take some trial and error before you find them. usefulshortcuts.com/alt-codes/punctuation-alt-codes.php autohotkey.com/
ive been trying to use local macros, but ` and ' do not do the job, i can assign macros, but cannot use it cause `local-name' does not do anything, global works just fine
here is my code for three dummies mw ne sou local region "mw ne sou" display "The local macro region contains: `region' " the display command returns "The local macro region contains: ", in other words it returns nothing, if i include `region' in regression model, none of the variables shows up in the model as if i did not include the local macro at all... hope that clarifies the problem
Well, that worked perfectly for me. It produced the following output: The local macro region contains: mw ne sou Can you explain how this does not work for you?
well, im not sure what else to explain beyond saying that this trivial command does not work on my PC for an unknown reason, i do exactly the same thing as i posted earlier and i get empty output, which is "The local macro region contains:" without the dummies mw ne sou, same happens when i include `region' into regression model, the dummies just not show up in the model. I tried it a month ago and it worked fine back than... i am using stata 13.1
you are awesome sir,
i was struggling with the stata macros.... you explained everything so beautifully
thanks a lot
Alan, u made hard stuff look simple.
Thanks for this insightful presentation
I'm glad you found it useful. Macros are used everywhere in Stata and are very powerful.
Thank you so much. It was so clear and helpful.
awesome video! Struggling so much until I watched this
Around 22:52 where you provide the explanation of the macro, please note that loop 3 should have hrs1 instead of wordsum...
+arvind sharma Thank you for finding this. I have not had a chance to look at the issue, but I will.
Best,
Alan
Wow! Amazing, this is the most detailed video I saw on youtube about local macros, thxs
Thank you for such a wonderful tutorial.
Thank you for these important macros.
thank you so much, can you please show how to rename a set of variables using loop and also to generate dummy variables using loop command
Hi Bugz, Stata has a command that allows you to rename a group of variables. I would rename variables using this command and not use any looping constructs. Here is an example:
sysuse auto, clear
rename (make price mpg rep78 headroom trunk ///
weight length turn displacement gear_ratio foreign) ///
(v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12)
You can read about the command by entering help rename group in the command window.
You don't say much about how you want to construct your dummy variables but I can give you two examples. The first uses numeric variables as inputs and divides them at their means, assigning 0 if a value is less than or equal to the mean and a 1 if it is greater than the mean and not missing. I put the variable generation in a loop. Here is the example:
sysuse auto, clear
foreach var of varlist price mpg weight {
summarize `var', meanonly
generate `var'dum = `var' >= r(mean) & `var'
🤩thank you so much for the very clear and extensive answer. I have several categories in the dummy. So as your suggestion it is the tabulate command I used.
gen v114=waters_dummyd
tabulate waters_dummyd, gen(water_srca)
gen imp_water_dd=1 if water_srca1==1
replace imp_water_dd=1 if water_srca2==0
For this, if there are categories from 1 - 20 I need to retype it 20 times and change the 1 or 0. I was wondering if I should do this way manually or if is there a macro to make this in a few lines.
@@bugzdesilva8216
I am confused by your code. I belive that your first two lines of code can be replaced by a single command like this:
tabulate v114, gen(water_srca)
You do not have to create a new variable to tabulate. Here is how this works with the auto.dta dataset:
sysuse auto, clear
tab rep78, generate(rep78dum_)
Because the variable rep78 has 5 categories, a total of 5 dummy variables are created. The variables form a linear combination so something like a regression model you would need to decide on a category to exclude. Nota bene: if using indicator variables in some model, you really should use Stata's factor notation (see help fvvarlist).
Your next two commands are confusing to me because I do not know how the original variable, v114, was coded. It looks like you are trying to take two conditions and code them equal to 1 and all other equal to zero. Here is an example, again, using rep78:
sort rep78
generate rep78dum = cond(1, rep78==1 | rep78==5, 0) if rep78
@@smilex3 Thank you so much !!! The last example you provided was really helpful to me. It solved the problem I faced. I was generating a binary variable assigning 1 or 0 per category to the main variable (ie: rep78). Your command made my dofile clear and smooth. Glad I'm following your channel !!
@smilex3 And one more clarification please.
if we want to generate a categorical variable by using the rep78 variable,
giving 1 if rep78==1 and 2 if rep78==2 and 3 if rep78==3 and 0 for both rep78==4 and rep78==5
how could we generate the above categories using the same command. Is it possible..
*sort rep78 generate rep78dum = cond(1, rep78==1 | rep78==5, 0) if rep78
Really miss your new videos. It is so incredible
Thank you for your video.
I would like to ask about bootstrapping. Could you give me an example that how to bootstrap with the foreach loop. For instance, to get standard error for elasticities from multiple regression.
Thank you.
Nice video. Very helpful. Thanks!
Is it possible that you can post some video about example how to do 30 regression estimate for the Dowjones stocks in just a short time rather than doing it by manually loading each firms data repeatedly over and over. and doing each seperate regression and then pile it in one file. have you some pointers on how to do such sort of a thing,
Hi Alan, Seeking your help in constructing a foreach loop. I have a pair of datasets (A & B) for each year from 2001 through 2010. I want to run a set of commands for database A for a given year first, then merge it with dataset B of same year. I want to repeat this for each year from 2001 through 2010. Appreciate your help. Thanks.. Alok
I'm trying to run below matrix of concentration index (ci). However, following error came up. Could you advise what's wrong with it.
type mismatch
r(109);
end of do-file
r(109);
sum r [aw=hhweight]
sca v_rank=r(Var)
foreach var of varlist count* {
sum `var' [aw=hhweight]
sca m_`var'=r(mean)
gen d_`var'=(2*v_rank)*(`var'/m_`var')
quietly {
regr d_`var' rank
matrix coefs=get(_b)
gen ci_`var'=coefs [1,1]
If "`var'"=="count5" {
matrix ci=coefs [1, 1]
}
if "`var'"~=̏count5̋ {
matrix ci=(ci, coefs[1,1])
}
}
}
Otgon,
This error message implies that either you are trying to numerically manipulate a string variable or apply a string operation to a numeric variable. The following Stata code demonstrates this idea. So, you will need to look at your variables and decide if you need to convert some or all to numerics or to strings. Here is the example code. Run one line at a time since the second generate will fail with an error.
Best,
Alan
/* Stata Code Follows */
sysuse auto, clear
describe mpg make
generate log_mpg=log(mpg) /* This works */
generate log_make=log(make) /* Data mismatch */
generate mpg_len=strlen(mpg) /* Data mismatch */
Great video! Many thanks!
Hi, Alan. Thanks for these videos! Can I use macro to regress in loop of firm and save the residuals of the regression as a variable using the minimum of 8 firms? What is the stata command for that? Thanks! Ana
I really enjoy your videos... though I was wondering if you have any that explainas how forvalue works in stata!
+Carolina Vargas I don't have a video explicitly about this but if you type "help forvalues" in the command window you can get a brief introduction. Do you have a specific problem in mind that we may be able to teas out together?
+Alan Neustadtl Im currently in a stata class and have to do some work. I have a data base(colombian) that is showing for each region the types of taxes and how much was recieved for each type of tax each year by region. So the variable nabes are something like this:
region | type_ of_ tax | 2000 | 2001 | 2002 | 2003 | 2004 |
there are 33 types of tax. they ask me to create a loop using "forvalues" with a sequence for each type of tax that has the following:
1) Number of iterations as big as the number of types of taxes (so 33)
2). Use command "summ"
3) extract the descriptive stats from each and save them in a matrix
**the matrix was created before and on the rows names were the types of tax and columns are mean sd min max sum. Right now the matrix is composed of "."
I dont know if this is very confusing
+Carolina Vargas So, this is a little confusing to me, but here is a try at using forvalues to produce descriptive statistics for different groups using the built-in auto.dta dataset:
sysuse auto, clear
forvalues i=1(1)5 {
summarize mpg if rep78==`i'
}
This ignores putting the results into a matrix which is more complicated. I know that the variable rep78 ranges from 1 to 5 so I can summarize another variable, mpg in this example, when rep78=1, then when rep78=2, and so forth.
But, in Stata this kind of operation can often be accomplished more simply using other means. This is probably not within the scope of your assignment, but the same out put can be achieved with just a single line of Stata code:
bysort rep78: summarize mpg if rep78!=.
And, this has the advantage of further grouping your summarized statistics. Here you can see the descriptive statistics of mpg broken down by foreign and domestic and within those categories by the five categories of rep78:
bysort foreign rep78: summarize mpg if rep78!=.
Is the first example what you needed?
+Alan Neustadtl I really enjoy your videos... though I was wondering if you have any that explainas how forvalue works in stata!
Dear Alan. Thank you for a great video. I have tried to replicate the commands you use in your video with regression models. In my own dataset I have created a list of independent vars and stored them in a local macro that I include in several logistic regression models that
each include different dependent variables. What I realized (at least I think I did) is that you have to create the local macro as well as run all the models including the local macro at once, i.e. you have to run several lines from your do-file in one go (as you do as well in your video). Is it possible to create a macro, which does not require that you run all of these commands at once? E.g. you may first create the local macro of independent variables, then spend some time doing some summary statistics, inspecting your data etc. and then, later in the stata session, run a model using the specified local macro of the independent variables. I hope this makes sense. Thank you very much. Kind regards, Martin (Denmark).
Greatings Professor, thank you so much for your videos. They are really clarifying to me.
I was wondering, why in the 41th line, don't you have to use the "`'" quotes to use the e() macros?.
julián, for reasons unknown to me, you do not need the special quotes on these Stata generated local macros. For example, the following all produce the same result with the exception that the last example is a string while the first two are numbers:
sysuse auto, clear
regress mpg weight
di e(mss)
di `e(mss)'
di "`e(mss)'"
Best,
Alan'
Thank you!
Hi Alan, I followed your instruction for constructing macro ( referring to your do file 27-30) but it's not working ( I am using STATA 14). Can you please suggest . I used the following command for my variables :
** hofstede to refer to the following three variables **
local hofstede Power_Distance Individualism Masculinity
di `hofstede'
reg WoB_Proportion `hofstede'
However the regression result is not showing coefficients for the three independent variables.
Please suggest. Thanks in advance.
Shams, without seeing the error from your program I can't be very specific about how to fix the issue. That said, the problem I see most often is the incorrect use of quoting in local macros. The left quote is not really a quote. It is the symbol underneath the tilde key. This is the tilde "~" and this is the quote on the same key "`". The right quote is " ' ". Here is some reproducible Stata code that works:
sysuse auto, clear
local ivs weight displacement
regress mpg `ivs'
Best,
Alan
Thank you Alan. I tried the same quote you mentioned. I cannot upload the error msg in the youtube comment box, is there any other way I can send you the snapshot of the error?
Thank you for sharing this.
I'm glad you found this video helpful!
Dear Alan. First, thanks for your videos!!!... I am trying to create a macro and foreach loop with the command spmap, but always STATA send the message "too many variables specified". This is the code:
local mld mldc_ilpc mldc_iapc mldc_impc
format `mld' %12.2f
foreach var of varlist `mld' {
spmap `mld' using comunascoord, id(id) clmethod(q) legend(size(medium) position(7)) fcolor(Blues2)
graph save `mld'
}
Javier, I cannot replicate your error. I adapted your code to run with the auto.dta dataset and it runs fine. Can you use that dataset and replicate your error? Then I might be able to dig a little deeper. I also wonder why you are using macros at all in your code with so few variables you could just use the format command. See the second to last line of the code below for an example.
Best,
Alan
sysuse auto, clear
desc length turn displacement
local mld length turn displacement
format `mld' %12.2f
desc length turn displacement
format length turn displacement %8.0g
desc length turn displacement
the `r(N)' and other scalars seems like a fantastically silly way for STATA to store these data. How can I look at the objects stored within r(), e(), etc? It seem like there should be a useful way of looking at what is stored in these lists before I'd use them...?
For example, I have a "flexible" stat summary table with rows, columns, and super columns. When I type "return list" after this table the only piece it shows is `r(N)' - where's the rest?
Jeff van Geete Unfortunately, there is no rest. When Stata commands are written, the developer decides what, if any, results are stored as local macros. In the case of the table command (I think this is what you are referring to) only one result, the sample size, is saved as a scalar.
I am not certain if this is silly (fantastically) or not, but saved results in macros are often very useful if you want to use these results in your own programming to calculate something outside of the command, proper.
Best,
Alan
Alan Neustadtl As in most other stat programs / packages, I agree that having the results is useful for later calculation. For example, all (lm) linear models in R contain these results in their structure, without having to issue an extra command. I quite like Stata, but on this one issue look no further than the curious assignment of ` and ' (I can think of no other language that demands dissimilar quotes). Truly head-scratching.
Jeff van Geete I am not sure why you find using `' to delimit local macros. All programming languages have these kind of programming syntax. Suppose you could define a local macro as "local #newmacro r(N)" and then refer to it as "#newmacro". How is the decision to use a pound symbol to refer to macros any less curious than using ` and ' delimiters?
Unfortunately, all programming languages do what they do regardless of our dreams, wishes, and desires! So, for many of us that means learning the ins and outs and curiosities of many programming languages.
Alan Neustadtl if a language wanted you to use ( and ] to open and close arguments, would you think that's odd? why use mismatched quotes? just to be different? programming languages are supposed to follow a discernible (and yes, learnable) logic, almost rule #1 - or? i use `language function()` all the time in markdown (as in `r nrow(data)`), as has been standard since probably before my time. matching these opening and closing symbols is standard - or should be.
No more odd than many, many other programming conventions which is exactly my point. What is odd in R to me is not to an R programmer. What is odd to the R programmer in Stata is not to me. And no, using ( and ] is no more odd than using ` and ' or #macroname . I suppose that using the accent grave and a quote may have been selected as delimiters since they are similar, but not equal to single and double quote pairs. But I speculate, and my wishes and desires for what Stata "should do" are of no consequence--Stata does what it does (same for all other programming languages.
Great help!
this is particularly useful
thanks, its so helpful
I'm glad you found the video useful!
Initial tune is dope
A great Canadian singer-songwriter named Stan Rogers. One of my favorite songs of his is called "Northwest Passage". Prime Minister Stephen Harper called it the unofficial national anthem of Canada. You can listen to it here: ua-cam.com/video/Fk2cNWW5FU0/v-deo.html
Thanks a lot!
Valérie Julie Brousseau Thank you for your comment. I'm glad you found this video useful.
Alan Neustadtl, you could try "Alt+96" and/or "Alt+39" for the apostraphes. For even smoother workflow with your surface pro2, you could assign those to an autohotkey.
Having said that, I am pretty sure you can find the apostraphes even without using the alt-combinations. It will probably just take some trial and error before you find them.
usefulshortcuts.com/alt-codes/punctuation-alt-codes.php
autohotkey.com/
ive been trying to use local macros, but ` and ' do not do the job, i can assign macros, but cannot use it cause `local-name' does not do anything, global works just fine
Can you share a reproducible example that fails? Without an example, it is difficult to comment on how to address your problem.
here is my code for three dummies mw ne sou
local region "mw ne sou"
display "The local macro region contains: `region' "
the display command returns "The local macro region contains: ", in other words it returns nothing, if i include `region' in regression model, none of the variables shows up in the model as if i did not include the local macro at all... hope that clarifies the problem
Well, that worked perfectly for me. It produced the following output: The local macro region contains: mw ne sou
Can you explain how this does not work for you?
well, im not sure what else to explain beyond saying that this trivial command does not work on my PC for an unknown reason, i do exactly the same thing as i posted earlier and i get empty output, which is "The local macro region contains:" without the dummies mw ne sou, same happens when i include `region' into regression model, the dummies just not show up in the model. I tried it a month ago and it worked fine back than... i am using stata 13.1
when i type su `region' i get a summary for all variables in the dataset...