»  Home »  Resources & support »  FAQs »  Column-mode selection in the Do-file Editor

How can I use column-mode selection (select rectangles) and editing in the Do-file Editor?

Title   Column-mode selection in the Do-file Editor
Author Dan (Mia) Lv, StataCorp

A short answer

This keyboard shortcut varies across different operating systems.

In Windows, you can hold the Alt key and make your selection using the mouse.

In Unix, use the Ctrl key instead of the Alt key.

In Mac, use the Option key instead.

After you make a selection, you can type, delete, copy, and paste text in column mode.

A long answer

If you have ever entered or edited your data in a text editor, you may find it helpful to use column-mode selection. Here we show several examples using the Do-File Editor in Windows.

One advantage of column-mode selection is that you can delete or append a variable easily if your data are in fixed format. For example, you are trying to create a dataset using the following commands.

input mpg	rep78	headroom	trunk	weight	length	turn	displacement
	22	3	2.5		11	2930	186	40	121	
	17	3	3.0		11	3350	173	40	258	
	22	.	3.0		12	2640	168	35	121	
	20	3	4.5		16	3250	196	40	196	
	15	4	4.0		20	4080	222	43	350	
	18	3	4.0		21	3670	218	43	231	
	26	.	3.0		10	2230	170	34	304	
	20	3	2.0		16	3280	200	42	196	
	16	3	3.5		17	3880	207	43	231	
	19	3	3.5		13	3400	200	42	231	
	14	3	4.0		20	4330	221	44	425	
	14	2	3.5		16	3900	204	43	350	

Now you want to modify your code to exclude the variable weight. If you use Windows, you can hold the Alt key and select the corresponding text, as shown in Figure 1.

Screenshot. Column weight selected.

Figure 1

Then, you can drop the selected part by clicking on the Delete key.

Assume now that you want to add a string variable unit with content “miles per gallon” next to the variable mpg. You can hold the Alt key and drag one vertical line on the right side of mpg observations, as shown in Figure 2.

Screenshot. Vertical line dragged to right of mpg.

Figure 2

With this selected, you type “mile per gallon”. You will see that this text is inserted in each selected row, as shown in Figure 3.

Screenshot. mile per gallon added

Figure 3

A single click in any place disables column-mode selection.

Copying and pasting a rectangle of data is very convenient with column-mode selection. Assume that you want to move the variable turn to the first column. You can first select the corresponding text just as we did before and right-click to cut it.

Screenshot. Column turn selected

Figure 4

Then, you move your pointer to the upper-left corner where you want to paste the data and right-click to paste. You will see the content of the variable turn has been moved to the first place on the left side.

Screenshot. Column turn moved to first column

Figure 5

As we mentioned in the beginning of the FAQ, this keyboard shortcut varies across different operating systems. You can follow the instruction for your operating system to perform these types of edits using column-mode selection.





The Stata Blog: Not Elsewhere Classified Find us on Facebook Follow us on Twitter LinkedIn Google+ YouTube Instagram
© Copyright 1996–2018 StataCorp LLC   •   Terms of use   •   Privacy   •   Contact us